08 Jul PHP GET Method
For sending information to the web server, use PHP GET method. It produces a long string, whenever you send information. This string can be seen in the address bar as well as in server logs. Here’s how it will be visible,
1 2 3 |
name1=value1&name2=value2 |
Let’s learn about some interesting points about the GET method,
- Never use GET, if you want to send passwords.
- Information sent via the GET method isn’t hidden and can be seen in the URL.
- There is a limitation of 1024 characters while sending information through GET.
- PHP superglobal variable $_GET is used to collect form data with GET.
- You can never send images, or documents, to the server, via GET.
Example
Here, we have two files. The first one is HTML form,
1 2 3 4 5 6 7 8 9 10 11 12 |
<html> <body> <form action="success.php" method="get"> Name: <input type="text" name="name"><br> Age: <input type="number" name="age"><br> <input type="submit"> </form> </body> </html> |
Here’s the output,
The second file is success.php which will open if the form submission is successful. We’re using superglobal variable $_GET to collect form data with GET.
1 2 3 4 5 6 7 8 9 10 |
<html> <body> Hi, User: <?php echo $_GET["name"]; ?><br> Your age: <?php echo $_GET["age"]; ?> </body> </html> |
Here, you can see the output. The URL shows the name and age information since we used the GET method. There’s a limitation of 1024 characters while sending information through GET. And since you can see the information in the URL, it is considered insecure. So, never use GET to send passwords.
No Comments