简体   繁体   中英

$variable = header location

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

Header returns type of void. You can not expect $error to be anything besides null .

If you are getting a 500 error, it is caused by something else (syntax error?).

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; .

You can't assign the 'header' function to anything, as it would always return void. A bit useless.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM