Maison  >  Article  >  développement back-end  >  php header跳转失效怎么办?解决方法

php header跳转失效怎么办?解决方法

WBOY
WBOYoriginal
2016-07-25 08:52:291263parcourir
有关php header跳转失效的解决方法,header跳转页面时的一些注意事项,若一定要在输出之后再处理header信息,可以使用 ob_start() ob_end_flush() 来缓存内容。

php header跳转失效的解决方法

一、问题: header(\"location: $url\")跳转失败,只是输出结果,以往要确认检查,$url的值获取的是否正确,所以在前面加了echo $url;来调试用,结果就导致了header函数的无效。

二、解决方法: 在php中用header("location:test.php")进行跳转要注意以下几点: 1、location和“:”号间不能有空格,否则会出错.//phpfensi.com 2、在用header前不能有任何的输出,包括include的页面中标签“?>”后不能有空格. 3、header后的php代码还会被执行.

php的 header 跳转之前不能有任何内容输出,因为php开始执行时就已经向浏览器送出http头信息,之后就不再允许更改了. 若一定要在输出之后再处理header信息,可以使用 ob_start() ob_end_flush() 来缓存内容,等到header继续再发送内容.

更简单的办法: 修改php.ini,找到 output_buffering=off 修改为: output_buffering=4096



Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn