Simple PHP Redirect Script
I recently needed a way to redirect users from a landing page to my main content pages on a website. I decided to do this via a server side PHP script instead of JavaScript to ensure the maximum number of users actually get redirected.
Here’s the PHP code:
<?php header( ‘Location: http://www.example.com/some_path’ ) ; ?>
One important thing to note is that this code must be the very first thing sent to the browser, otherwise it won’t work. So don’t have something like the following example.
<html>
<title>Redirecting you now…</title>
<?php header( ‘Location: http://www.example.com/some_path’ ) ; ?>
This example won’t work because there is other text sent to the browser before the redirection code.
I’ve included an example of a JavaScript redirect also, just so you can get an idea of how it works because someone may need it one day.
<HEAD> <SCRIPT language="JavaScript"> <!-- window.location="http://ramonecung.com"; //--> </SCRIPT> </HEAD>
