Home arrow PHP arrow Page 2 - PHP GET and POST Functions

Understanding $_GET in PHP - PHP

PHP GET and POST are predefined global and associated array variables used for retrieving user submitted information passed using HTTP GET and HTTP POST methods. They are mostly used with PHP web form applications where you need to interact with your user input. This tutorial is a complete guide to using PHP GET and POST functions with illustrative examples and security considerations.

  1. PHP GET and POST Functions
  2. Understanding $_GET in PHP
  3. Best PHP Practices and Security Considerations
By: Codex-M
Rating: starstarstarstarstar / 8
April 20, 2011

print this article



PHP $_GET works similarly to $_POST. It is used when:

  1. The web form is using HTTP GET Method.
  2. You need to pass the value in the query string variable of URL. This makes the submitted value visible to the users.
  3. You need to make the URL available for future use such as the ability to be bookmarked.
  4. You only need to pass a limited amount of characters. Since the value of $_GET gets appended in the URL as a value of the query string variable, the limitation depends on the URL limit which is around 2083 characters: http://support.microsoft.com/kb/208427.

Like $_POST, $_GET is also a predefined associated array variable with global scope.

Basic Example (basicget.php):

<title>Basic Application for PHP $_GET</title>
<form action="processor.php" method="get">
Please enter your favorite food: <input name="favoritefood" type="text" />
<input type="submit" name="submit" value="Submit this form">

The PHP script(form handler/processor):

//retrieve favorite food from the web form which is submitted using HTTP GET Method
$favoritefood= $_GET['favoritefood'];

//Output user favorite food back to the browser
echo $favoritefood;

When the sample code is run, the passed value of the form will be appended in the URL:


In the above URL, the query string variable is “favoritefood” with the submitted value  of “italian pasta” using the HTTP GET method.  You can re-use this URL by bookmarking because the submitted value is appended in the URL.

Warning: Do not use the above sample code for practical applications because it is not secure. See last section of this tutorial.

>>> More PHP Articles          >>> More By Codex-M

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: