faqts : Computers : Programming : Languages : PHP : Common Problems : Forms and User Input

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

6 of 9 people (67%) answered Yes
Recently 6 of 9 people (67%) answered Yes

Entry

How do I redirect a brower to the approtite page pendding on user input from a form?

Oct 16th, 2004 15:32
Philip Olson, Glenn Sams,


Assuming "answer" is the name of the form element, add various options
to the redirect array and it should work.
<?php
$baseurl   = 'http://www.example.com/troubleshooting/';
$redirects = array('bad'    => 'something-bad.html',
                   'good'   => 'something-good.html',
                   'other'  => 'other.html'
                   );
if (in_array($_POST['answer'], array_keys($redirects))) {
    header('Location: ' . $baseurl . $redirects[$_POST['answer']];
    exit;
} else {
    echo "Not sure what to do, choose an appropriate action\n";
    exit;
}
?>