GET and POST method in PHP


The GET Method

The GET method sends the enclosed encoded user information to the GET method page request. Page and encoded information are separated? Character.

http://www.test.com/index.htm?name1=value1&name2=value2 


The GET method creates a long string that appears in your server log in the browser server
Location: Box

• The GET method is restricted to sending only up to 1024 characters.
• If you have passport or other sensitive information, do not use the GET method anytime
Server.
• GT can not be used to send binary data, such as images or word documents, on the server.
• Data sent by GET method can be accessed using the QUERY_STRING environment variable.
• PHP provides $ _GET associative array for accessing all the information sent using GAT
way.

Example - 

<?php
 if( isset($_GET["name"]) && isset($_GET["age"] ))
 {
 echo "Welcome ". $_GET['name']. "<br />";
 echo "You are ". $_GET['age']. " years old.";
 exit();
 }
?>
<html>
<body>
 <form action="<?php $_PHP_SELF ?>" method="GET">
 Name: <input type="text" name="name" />
 Age: <input type="text" name="age" />
 <input type="submit" />
 </form>
</body>
</html>



The POST Method

Post method transfers information via HTTP header, information is encoded
In the case of GET method, it has been described and put in the title named QUERY_STRING.  

There is no restriction on the data size to send the post method.
• POST method can also be used to send binary data along with ASCII.
• Data sent through POST method is sent through HTTP header so security depends on HTTP
Creating a Cure By using secure HTTP (https) you can ensure that your information is safe
• PHP provides $ _POST associate arrays to access all the information sent by using GET
way.

Example - 

<?php
 if( isset($_POST["name"]) && isset($_POST["age"] ))
 {
 echo "Welcome ". $_POST['name']. "<br />";
 echo "You are ". $_POST['age']. " years old.";
 exit();
 }
?>
<html>
<body>
 <form action="<?php $_PHP_SELF ?>" method="POST">
 Name: <input type="text" name="name" />
 Age: <input type="text" name="age" />
 <input type="submit" />
 </form>
</body>
</html>

The $_REQUEST Variable

The $_REQUEST variable contains the contents of both $_GET, $_POST, and $_COOKIE. The PHP $_REQUEST variable can be used to get the result from form data sent with both the GET and POST methods.

Example - 
<?php
 if(isset($_REQUEST["name"]) && isset($_REQUEST["age"] ))
 {
 echo "Welcome ". $_REQUEST['name']. "<br />";
 echo "You are ". $_REQUEST['age']. " years old.";
 exit();
 }
?>
<html>
<body>
 <form action="<?php $_PHP_SELF ?>" method="POST">
 Name: <input type="text" name="name" />
 Age: <input type="text" name="age" />
 <input type="submit" />
 </form>
</body>
</html> 

Name: Age:
Share on Google Plus

About It E Research

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment