Pass form variables(get post) to another page and superglobals

Posted under » PHP on 13 March 2009

This is how you get data from a form.

The post method is the preferred method because the variables are hidden from view thus making the URL look much neater.

$name = $_POST["name"];
$email = $_POST["email"];

This is how you get data from the URL method.

$name = $_GET["name"];
$email = $_GET["email"];

This may not work if you have some of these characters; single quote ('), double quote ("), backslash (\) and NUL (the NULL byte) when trying to insert them to MySQL. Usually you have to convert them like so.

$name = addslashes($_GET["name"]);

Btw... several predefined variables in PHP are "superglobals", which means they are available in all scopes throughout a script. There is no need to do global $variable; to access them within functions or methods. These superglobal variables are:

When it used to be just $QUERY_STRING it is now $_SERVER['QUERY_STRING'];  

web security linux ubuntu GIT svn Raspberry apache mysql php drupal cake symfony javascript Ajax css