Predefined variables
From JumbaWiki
(Redirected from PHP predefined variables)
Contents |
PHP provides a large number of predefined variables that are available to any script which it runs.
Below is a list of some common variables that you might find useful.
HTTP GET variables: $_GET
The most common $_GET usage would be via form posting. When a form is posted via the "get" method (<form .... method="get">), the $_GET variable returns an array containing all your submitted form variables.
Example
form.php
<form action="" method="get" name="Form">
<input type="text" name="Field1">
<input type="submit" name="Submit" value="Submitted">
</form>
<pre>
<?php
if ($_GET['Submit']) {
print_r($_GET);
}
?>
</pre>
This will return the following under the form when submitted:
Array ( [Field1] => Example Text [Submit] => Submitted )
HTTP POST variables: $_POST
The most common $_POST usage would be via form posting. When a form is posted via the "post" method (<form .... method="post">), the $_POST variable returns an array containing all your submitted form variables.
Example
form.php
<form action="" method="post" name="Form">
<input type="text" name="Field1">
<input type="submit" name="Submit" value="Submitted">
</form>
<pre>
<?php
if ($_POST['Submit']) {
print_r($_POST);
}
?>
</pre>
This will return the following under the form when submitted:
Array ( [Field1] => Example Text [Submit] => Submitted )

