header('Location:') not redirecting

老子叫甜甜 提交于 2019-12-02 04:53:37

You need to make sure you don't output anything before the header tag. Since it was working before, I assume it's not an error where you are echo'n stuff before the call to header, and since you see no output, I assume it is outputting white-space. There are a few places where some whitespace and/or invisible characters can sneak into a file:

Put the cursor before your opening PHP tag (<? or <?php) and hit backspace a few times, then hit delete to delete the < and then retype the <. That will make sure there are no invisible characters being output to the browser before your headers.

Then go through any files that are included by that file, and do the same thing, as well as delete any ?> that you have at the end of the file. If those files include any othe files repeat this on them.

If you want to use header(), you must not echo anything prior to it.

Are you outputting anything before calling header()?

If so, put ob_start() at the beginning of your script or make sure you're not echoing anything before header() is called

add ob_start(); to the beginning of your script and add ob_end_flush(); to the end of your script to avoid this issue.

ob_start(); will turn output buffering on and ob_end_flush(); will send the contents of the topmost output buffer and turn this output buffer off.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!