View Full Version : Redirects


Andrew Green
10-23-2005, 03:53 AM
With all the moving of sites going on I got inspired, here's how to redirect a page using php.



<?php
header("Refresh: 3; URL=http://buffaloit.com");
echo "
<html>
<body>
<p>will redirect in 3 sec</p>
</body>
</html>
";
exit();


To do it without a timer change the header:


<?php
header("Location: http://buffaloit.com");
exit();
?>


The header line has to be sent before anything else or it will give a error message.


The second method is useful if you are processing something and want to only process it once. Like a sql query, or submitting a form.

So you would process the form, redirect then instead of displaying something, redirect, even if to the same page. This will let you maintain back - forward - refresh navigation without forms getting resubmitted or queries rerun that aren't supposed to be (ex- inserts)

BlueDragon1981
10-23-2005, 10:12 PM
When I start working with php later on next year...(hopefully anyway) that will come in handy.