Don Alexander Eckford's Redirect Example

This is Exercise 2 on Page 266 (end of Chapter 9) in "Beginning PHP 5.3".

Redirect:



 

CODE FOLLOWS

<?php

    error_reporting
(E_ALL);    // set error reporting to all

    
$self basename($_SERVER['SCRIPT_NAME']);
    
$where = isset($_POST['where']) ? $_POST['where'] : null;
    
$step = isset($_POST['step']) ? $_POST['step'] : 0;

    
$allowed_urls = ['https://amazon.com''https://amazon.ca''https://amazon.co.uk'];

    if (
$step == && in_array($where$allowed_urls)) {
        
header("Location: $where");
        exit(
0);
    }

    include(
'includes/header.php');
?>
    <h1>
        Don Alexander Eckford's Redirect Example
    </h1>

    <p>
        This is Exercise 2 on Page 266 (end of Chapter 9) in "Beginning PHP 5.3".
    </p>

    <form action="<?php echo htmlspecialchars($self); ?>" method="post">
        <fieldset>
            <legend>Redirect:</legend>
            <input type="hidden" name="step" value="1">

            <label for="amazon_com">Amazon.com</label>
            <input type="radio" id="amazon_com" name="where" value="https://amazon.com" checked> <br>

            <label for="amazon_ca">Amazon.ca</label>
            <input type="radio" id="amazon_ca" name="where" value="https://amazon.ca"> <br>

            <label for="amazon_uk">Amazon.co.uk</label>
            <input type="radio" id="amazon_uk" name="where" value="https://amazon.co.uk"> <br><br>

            <input type="submit" name="submit" value="Submit">
        </fieldset>
    </form>

<?php
    
include('includes/footer.php');
?>