Popular script sites

The Five Dollar Script Archive HOTScripts.com
Freshmeat.net
cgi-bin.com
MATTs Script Archives
Script Search
Script Resources
Webmaster Scriptz.com

Redirect PHP Script

Redirecting a visitor or the browser is required for a variety of reasons. If a a page is temporarily down you can use a HTTP 302 redirect. Same way permanent redirection is HTTP 301 redirection. All the 3xx are different types of redirection and out of them 301 and 302 are the most common. HTTP 301 permanent redirection is well accepted by search engines also. We will discuss the PHP redirection method here.

Using Location Header function to redirect a page.
This script works when we have not sent any php or html command to out put any thing in the browser. Care should be taken not to send anything to the browser after the header redirection using location command.

<? header ("Location: http://www.adinstall.com/"); ?>
/* Redirect browser to adinstall.com web site */ exit; // Closes further script execution .

You can see the above code will redirect the page to a new URL.

Now, let's write the code for 301 redirection (page permanently moved )

<? header("HTTP/1.1 301 Moved Permanently"); header ("Location: http://www.adinstall.com/pretend.php"); exit; ?>

It comes in handy to know how to redirect one page to another page. PHP makes it easy! This tiny piece of code shows the syntax that causes the visitor to redirect to a different URL than the one they 'landed' on. The following php script redirects the user to /index.php within the same site:

<? header('Location: /index.php'); ?>

The redirection target can be any suitable URL as could be used in the href parameter of an address tag (such as http://www.adinstall.com/index.php).

The header function sends raw header data to the client web browser and in this case sends a 302 status code which instructs the browser to redirect to the given location.

Free Scripts Index  Back to Free Scripts Index...

What's New?

Support Desk Script

best autoresponder script The BEST Autoresponder.

Affiliate Link Encryptor!



Link Machine, Link Directory Script


Green Web Hosting
Sustainable Living