To send visitors to introduction.html when they submit “intro” or “introduction,” check the submitted field in the PHP handler, send a Location header, then call exit. The redirect must happen before PHP outputs any HTML or other content.
Set the form to submit to your PHP handler
The form’s action names the endpoint that receives the submission. Set its method to post if you plan to read the value from $_POST, and make sure the input’s name matches the key your PHP code reads:
As an Amazon Associate I earn from qualifying purchases.
<form action="route.php" method="post">
<label for="destination">Destination</label>
<input id="destination" name="destination" type="text">
<button type="submit">Continue</button>
</form>
Here, the submitted text is available to route.php as $_POST['destination']. The button does not need a name when the handler only needs the text field. The archived SitePoint Forums discussion illustrates why field names and form methods need to agree: examples in the exchange changed names and did not consistently show an explicit method.
Check the value and redirect before output
Put the routing logic at the start of route.php, before a doctype, HTML, whitespace outside PHP tags, or any other output:
#1 Best Overall
<?php
$destination = $_POST['destination'] ?? '';
if ($destination === 'intro' || $destination === 'introduction') {
header('Location: introduction.html');
exit;
}
// Continue normal processing for other values.
?>
The two accepted values are compared exactly, so capitalization differences or extra spaces do not match. If you want case-insensitive or whitespace-tolerant input, normalize it deliberately before the comparison rather than silently broadening what is accepted.
PHP’s header() manual says headers must be sent before actual output. A Location header ordinarily produces a 302 redirect unless a 201 or 3xx status has already been set. Calling exit prevents the handler from continuing into code intended for the non-redirect path.
Rank #2
Handle values that do not match
When the submitted value is neither intro nor introduction, the condition is false and PHP continues. Replace the comment with the ordinary form-processing behavior, such as validation and a response or a save operation. Do not assume an unmatched value is safe or valid merely because it did not trigger the redirect.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Clear out junk files and repair common Windows errors3Fix the driver behind crashes, sound loss and screen glitchesKeep redirect destinations fixed or allowlisted
For this example, a fixed destination is simplest: the user’s text decides whether to redirect, but it is not inserted into the destination URL. If a form lets users choose among several pages, map accepted values to a fixed allowlist of destinations and redirect only to a matched entry. Avoid passing arbitrary submitted text directly to header('Location: ...'); the forum discussion suggests restricting destinations, but its example should not be treated as a tested production implementation.
Quick Recap
Rank #4
Common reasons the redirect fails
- “Headers already sent”: move the redirect logic before all output, including whitespace before the opening PHP tag.
- The condition never matches: confirm that the form uses
method="post", that the input is nameddestination, and that the handler reads$_POST['destination']. - The form reaches the wrong script: check that its
actionpoints to the PHP file containing the routing logic. - PHP continues after sending the redirect: place
exitimmediately afterheader().
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




