All pastes #677234 Raw Edit

Miscellany

public text v1 · immutable
#677234 ·published 2007-08-31 20:40 UTC
rendered paste body
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:
    http://example.org/index.php?list=user&orderby=name&direction=asc
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:
    echo $_GET[’list’];
You can create arrays by using array notation...
    http://example.org/index.php?list=user&order[by]=column&order[dir]=asc
..and then access them using the following syntax:
    echo $_GET[’order’][’by’];
    echo $_GET[’order’][’direction’];
100 ” Web Programming
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 en-
coded using a particular mechanism that, in PHP, is provided by the urlencode()
function:
   $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.