Tedd's $REQUEST[] Array Example:
Be carefull using the $_REQUEST[] Array because of the order that PHP places
the GET and POST variables.
In addition, it might be a security concern in that it is not clear where the data came
from that's found in the $_REQUEST[] array. It may have been provided via a $_GET[]
or a $_POST[]. As such, it is usually "best" to use variables provided by
GET[] and POST[] directly and not use $_REQUEST[].
Results:
$_POST Array()
Array
(
)
$_GET Array()
Array
(
)
$_REQUEST Array()
Array
(
)
CODE FOLLOWS
<?php
include('includes/header.php');
// code
error_reporting(E_ALL); // set error reporting to all
$self = basename($_SERVER['SCRIPT_NAME']);
$post_var = isset($_POST['post_var']) ? $_POST['post_var'] : '';
$get_var = isset($_GET['get_var']) ? $_GET['get_var'] : '';
// filter all input for Browser output
$post_var = htmlentities($post_var);
$get_var = htmlentities($get_var);
?>
<h1>
Tedd's $REQUEST[] Array Example:
</h1>
<p>
Be carefull using the $_REQUEST[] Array because of the order that PHP places
the GET and POST variables.
</p>
<p>
In addition, it might be a security concern in that it is not clear where the data came
from that's found in the $_REQUEST[] array. It may have been provided via a $_GET[]
or a $_POST[]. As such, it is usually "best" to use variables provided by
GET[] and POST[] directly and not use $_REQUEST[].
</p>
<form action="<?php echo($self); ?>" method="post">
<label for="post_var">Post Variable</label>
<input type="text" size="10" id="post_var" name="post_var" value="<?php echo($post_var); ?>">
<br>
<input type="submit" name="submit" value="Submit via POST">
</form>
<br>
<form name="my_form" action="<?php echo($self); ?>" method="get">
<label for="get_var">Get Variable</label>
<input type="text" size="10" id=get_var name="get_var" value="<?php echo($get_var); ?>">
<br>
<input type="submit" name="submit" value="Submit via GET">
</form>
<br>
<h2>Results:</h2>
<hr>
<?php
echo('<pre>');
echo('<br>');
echo('$_POST Array()');
echo('<br>');
print_r($_POST);
echo('<br>');
echo('<br>');
echo('$_GET Array()');
echo('<br>');
print_r($_GET);
echo('<br>');
echo('$_REQUEST Array()');
echo('<br>');
print_r($_REQUEST);
echo('<br>');
echo('</pre>');
include('includes/footer.php');
?>