user198729
user198729

Reputation: 63636

Sometimes redirecting failed mysteriously in PHP?

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

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

Upvotes: 0

Views: 229

Answers (4)

chelmertz
chelmertz

Reputation: 20601

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

Upvotes: 1

Tyler Carter
Tyler Carter

Reputation: 61567

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.

Upvotes: 1

Aiden Bell
Aiden Bell

Reputation: 28386

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.

Upvotes: 3

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798626

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

Upvotes: 2

Related Questions