开发者

Sometimes redirecting failed mysteriously in PHP?

开发者 https://www.devze.com 2022-12-16 09:36 出处:网络
@header(\'Location: \' . $uri); But it only seldom happens,what\'s the p开发者_如何学JAVAroblem?Don\'t use @ to supress the error and check your logs, it is one of a few things:
@header('Location: ' . $uri);

But it only seldom happens,what's the p开发者_如何学JAVAroblem?


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.


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


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号