Forums

PHP

This topic is locked

PHP conditional redirect

Posted 11 Oct 2006 12:23:13
1
has voted
11 Oct 2006 12:23:13 simon logan posted:
I'm currently building a site using PHP, usually I work with ASP and so I'm needing to adjust to the different ways of doing things but I've come across one problem which I hope you can help with.

Basically I want to have a conditional redirect so IF certain conditions are met the user is redirected to another page which I could do is five seconds flat in ASP using the redirect function but I'm damned if I can find a simple equivelant for PHP. I'm aware of the header function but this only seems to work as a base redirect - when I put it into a conditional region I was getting header errors.

Is there is simple function that I can use to redirect a user based upon a condition being met in PHP?

Replies

Replied 17 Oct 2006 07:10:46
17 Oct 2006 07:10:46 micah santos replied:
i encountered the same problem when it was my first time working with PHP redirection.

but here's how:

Note: do not use echo, or else, you will get an error.

<?php

if(!$input_invalid)
{
header("Location: invalid.php";
exit();
}
else
{
header("Location: valid.php";
exit();
}
?>

Reply to this topic