PHP $_GET & PHP $_POST
The $-GET variable:
The $-GET variable is an array of variable names and values sent by the HTTP GET method.The $-GET variable is used to collect values from a form method="get".Information sent from a form with the GET method is visible to everyone and it has limits on the amount of information to send maximum like hundred characters.
When using this GET variable names and values are displayed in the URL. So this method should not be used when sending passwords or other sensitive information.
The variables are displayed in the URL, it is possible to bookmark the page.
The variables are displayed in the URL, it is possible to bookmark the page.
Example:
<form action="welcome.php method="get">
Name: <input type="text" name="name" />
Age : <input type="text" name="age" / >
<input type="submit" />
</form>
When the user clicks the "submit" button, the URL sent could look something like this
http ://www.aaa.com/welcome.php?name=XXX&age=30
When the user clicks the "submit" button, the URL sent could look something like this
http ://www.aaa.com/welcome.php?name=XXX&age=30
The $-POST variable:
The $_post variable is an array of variable names and values sent by the HTTP method.
The $_POST variable is used to collect values from a form with method="post".Information sent from a form with the POST method is invisible to others.
Example:
<form action="welcome.php method="post">
Name: <input type="text" name="name" />
Age: <input type="text" name="age" / >
<input type="submit" />
</form>
When the user clicks the "submit" button, the URL will not contain any form data, and will look like this:
http ://www.aaa.com/welcome.php
When the user clicks the "submit" button, the URL will not contain any form data, and will look like this:
http ://www.aaa.com/welcome.php
Reason for using $_POST:
1.What are variables sent with HTTP POST are not shown in the URL
2.We don't worry about the variables length
The $-REQUEST variable:
1. The PHP $_REQUEST variable contains the contents of both $_GET,$_POST,$_COOKIE.
2. The PHP $_REQUEST variable can be used to get the result from form data sent with both the GET and POST methods.
Example:
Wecome<?php echo $_REQUEST["gender"]; ?>.<br />
You are coming from <?php echo $_REQUEST["address"]; ?>UK.
No comments:
Post a Comment