zend_php_5_certification_study_guide

Page 119

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 encoded 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.

Using POST When sending the form we introduced above with the method attribute set to post, the data is accessible using the $_POST superglobal array. Just like $_GET, $_POST contains one array element named after each input name. if ($_POST[’login’]) { if ($_POST[’user’] == "admin" && $_POST[’pass’] == "secretpassword") { // Handle login } }

In this example, we first check that the submit button was clicked, then we validate that the user input is correct. Also, similarly to GET input, we can again use array notation: <form method="post"> <p> Please choose all languages you currently know or would like to learn in the next 12 months. </p> <p> <label> <input type="checkbox" name="languages[]" value="PHP" /> PHP </label> <label>


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.