GET and URLs
GET and URLs
When a form is submitted using the GET method, its values are encoded directly in
the query string portion of the URL. For example, if you submit the form above by
entering user in the List box and choosing to sort by Name in Ascending order, the
browser will call up our index.php script with the following URL:
As you can see, the data has been encoded and appended to the and of the URL for
our script. In order to access the data, we must now use the $_GET superglobal array.
Each argument is accessible through an array key of the same name:
http://example.org/index.php?list=user&order[by]=column&order[dir]=asc ..and then access themusing the following syntax:
echo $_GET['order']['by']; echo $_GET['order']['direction'];Note that, clearly, there is nothing that stops you from creating URLs that already
contain query data- there is no special trick to it, other than the data must be encoded
using a particular mechanism that, in PHP, is provided by the urlencode()
$data = "Max & Ruby"; echo "http://www.phparch.com/index.php?name=" . urlencode ($data);The PHP interpreter will automatically decode all incoming data for us, so there is
no need to execute urldecode() on anything extracted from $_GET.