Page 1 of 1
Forwarding to another page if a condition isnt met
Posted: Wed Mar 12, 2003 7:43 am
by mayh3m
Another question from a newbie
Please tell me what statement I should use to go to another php page if a condition isnt met in an if statement.
I have used an include, but this includes the stuff on the previous page which I dont want.
Your help is greatly appreciated
Newbie
Posted: Wed Mar 12, 2003 7:58 am
by twigletmac
You can use
header():
Code: Select all
header('Location: http://www.mysite.com/someotherpage.php');
Mac
header doesnt work
Posted: Thu Mar 13, 2003 12:32 am
by mayh3m
Hi Twigletmac
I tried your suggestion, but it doesnt seem to work: This is what I'm trying to do
$result = mysql_query($query) or
die (mysql_error());
if (mysql_num_rows($result) == 0)
{
header('../helpdesk/newuser/form.php');
}
else
When I run it, it still goes and processes the "else" even if the result is zero. I've tried making the "header" the else part of the statement and the same is true. Please help
Posted: Thu Mar 13, 2003 12:39 am
by net7
You have to include "Location"
so it would look like
Code: Select all
header('Location: www.go.com');
exit();
that should work. remember to keep the "Location:" part in there. And for security reasons you can include exit();
Posted: Thu Mar 13, 2003 2:03 am
by twigletmac
As net7 said, you do need the 'Location: ' bit and you also need to read the manual page for the
header() function:
PHP Manual wrote:Note: HTTP/1.1 requires an absolute URI as argument to Location: including the scheme, hostname and absolute path, but some clients accept relative URIs. You can usually use $_SERVER['HTTP_HOST'], $_SERVER['PHP_SELF'] and dirname() to make an absolute URI from a relative one yourself.
There's an example on the page of how to do this.
Mac