tags:

views:

37

answers:

4
@header('Location: ' . $uri);

But it only seldom happens,what's the problem?

+2  A: 

Perhaps your script is sending some output before it for some reason. Remove the @.

Ignacio Vazquez-Abrams
+3  A: 

Don't use @ to supress the error and check your logs, it is one of a few things:

  1. Previous error output stopping the redirect?
  2. $uri is bad sometimes
  3. Something else in your code is bad.

Debugging is the answer.

Aiden Bell
Is there a general solution to debug this kind of issue?
+1  A: 

Well, it is most likely because the headers were already sent due to whitespace. You'll never know this because you have a @ sign in front of it that stops errors from being displayed.

Generally this whitespace might be caused by another error, or it might only happen when you include a certain file.

The other possibility is that $url is not properly formatted, or somehow the header just looks wrong to the browser. In which case the browser might choose to ignore it. Echo out the complete Header you are sending and make sure it looks right.

Finally, some browsers will stop redirecting if you have redirected too many times in a row.

Chacha102
+1  A: 

The header might not be sent right away. Always use die() after header().

chelmertz