Don Alexander Eckford's $REQUEST[] Array Example:

Be careful 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
    
ini_set('display_errors'1); // Display errors in development

    
$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_varENT_QUOTES'UTF-8');
    
$get_var htmlentities($get_varENT_QUOTES'UTF-8');

?>

    <h1>
        Don Alexander Eckford's $REQUEST[] Array Example:
    </h1>

    <p>
        Be careful 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="<?= $self?>" method="post">
        <label for="post_var">Post Variable</label>
        <input type="text" size="10" id="post_var" name="post_var" value="<?= $post_var?>">
        <br>
        <br> <!-- Breaks the line -->
        <input type="submit" name="submit" value="Submit via POST">
    </form>
    <br>
    <form name="my_form" action="<?= $self?>" method="get">
        <label for="get_var">Get Variable</label>
        <input type="text" size="10" id="get_var" name="get_var" value="<?= $get_var?>">
        <br>
        <br> <!-- Breaks the line -->
        <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');
?>