How to Create a PHP Redirect?
Posted · 1 min read
Outdated: The
header("Location: ...")approach still works in modern PHP, but note that the linked reference (W3Schools) is not an authoritative source. See the official PHP documentation for header(). Modern PHP frameworks provide redirect helpers that handle edge cases automatically.
Sometimes you want to hide an affiliate link, sometimes you may want to log each downloads of a file or just redirect the user to a site through your script. This is where PHP redirection comes handy.
The syntax is as follow:
header("Location: http://ephp.info"); die();
Just replace the URL with the page you want the user to be redirected to. The die() function is to make sure that the script ends execution if the redirection function failed for some reason.
Note: The word “Location” in the script must always start with a capital first letter. Otherwise, some older browsers might now follow the redirection.
If you want more info on PHP’s header function check out the W3School’s reference page.

