Reputation: 55
I can find hundreds of examples of "insert into header location", but I have not found any exaples where the $variable = header
location.
Is this possible:
$error=header('Location: http://www.example.com/error.php');
Basicly I had 3 conditions if row not found in mysql.
So I set up the 3 conditions:
if condition1 $error="a statement"
if condition2 $error="SELECT data
FROM table
WHERE data
= 'default'";
if condition3 $error=header('Location: example.com/error.php');
and then if($result->num_rows =0) $error
In my case $error
could be 3 different things, one of them being "redirect to the error page" but $error=header('Location:blah');
causes 500 server error.
I altered my code so that I could use header location in the conventional manner, but would still like to know if $var = header
location is possible.
The original code that prompted the question has been overwritten, I no longer have it to post.
Thanks Tom
Upvotes: 0
Views: 250
Reputation: 6908
http://php.net/manual/de/function.header.php
header() returns void, so, you can write $error=header('Location: http://www.example.com/error.php');
, but it wont do much.
After header('Location: ...');
you should call exit;
.
Upvotes: 0
Reputation: 762
You can't assign the 'header' function to anything, as it would always return void. A bit useless.
Upvotes: 0