PHP Front
The PHP website created by its users!
Home » PHP » PHP redirect


PHP redirect


Author
DescriptionRedirects users or bots to another page using php headers.
RatingThis script has been rated 4/5 (14 votes)

PHP Code


<?php

header
("Location: anotherpage.php");

?>




Rate it: Print Print

Comments


Annonymous / 5 Sep 05

simple, thanks
the T man / 9 Nov 05

cool...
Drew / 30 Jan 06

You can also recustomize this for:

[code]
function redirect($page, $error = "", $success = "")
{
$error_str = "";
$success_str = "";
$extra = "";
if(!empty($error))
$error_str = "?e=" . urlencode($error);
if(!empty($success))
$success_str = "?s=" . urlencode($success);
if(@$_REQUEST['force'] == 1)
$extra = "&force=1";

$relocate = "Location: " . $page . $error_str . $success_str;
$relocate = str_replace("&?e","&e", $relocate);
$relocate = str_replace("&?s","&s", $relocate);
header($relocate . $extra);
return;
}
[/code]

Thus, in the target page that you are redirecting to you could parse the error, success, or generic messages based on your reason for redirecting.
Name
Website
Your comment