0

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

3
  • 2
    What would you expect that to do? And yes, it's possible, it just may not do whatever you think this should do. Commented Jun 2, 2013 at 20:52
  • Please post more code form this file for us to ID what the problem might be. Commented Jun 2, 2013 at 20:59
  • I have completely rewritten the code, so I no longer have it to post. I could reconstruct it but since I write code at a snails pace, you would have to wait a couple days. My php knowledge is very limited. Commented Jun 2, 2013 at 21:20

3 Answers 3

2

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?).

Sign up to request clarification or add additional context in comments.

Comments

0

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

1 Comment

Must be why I couldn't find any examples of it. In my searching I also couldn't find any post like this saying it can't be done. Thank you to all who replied.
0

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

6 Comments

exit; (it's a keyword, so you don't need the ())
I know, but I usually add ()
You can write $error = header(...), it just won't do much.
It's possible that the OP rewrote the header function in which it does return something.
@Dave Now that's pretty darn hypothetical. :P
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.