PHP, Javascript and ASP Redirects

There are many ways to redirect people about. This guide covers some. It is important to stop execution of the script after sending the header, because otherwise the script will continue editing and could send conflicting headers, which will change your script.

PHP

A PHP redirect simply sends a 301 redirect to the user's browser. It works with search engines.

<?php
header("Location: http://example.com");
die();
?>

That will redirect the user to the website example.com. It must be placed before any text is sent to the user else it will generate a PHP error.

Javascript

A javascript redirect will tell the browser that is executing the script where it wants to redirect. It will not work with search engines or browser that do not execute javascript.

window.location="http://example.com";

Again that will redirect the user to example.com.

ASP

An ASP redirect works in the same way as a PHP redirect, sending the user to another page with a 301 redirect.

<% Response.Redirect "http://example.com";
Response.End();
%>

Again that will redirect the user to example.com.

0