PHP header() 不起作用 [英] PHP header() does not work

查看:46
本文介绍了PHP header() 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道为什么我的 header() 没有重定向吗?

Does somebody know why my header() does not redirect?

我的脚本的最后一部分是:

The last part of my script is:

  header("location: test.php");
  die('died');

它写道:

died.

:((((

它应该在它死之前重定向,但它没有.

It should has to redirect before it dies, but it does not.

你有什么想法吗?

推荐答案

很可能是你在调用 header() 之后 你正在向浏览器输出一些文本/HTML,这是一个不-不.如果在调用之前发送了单个空间的输出,您的 header() 调用也将被忽略.

It's probably that you're calling header() after you are outputting some text/HTML to the browser, which is a no-no. Your header() call will be ignored if even so much as a single space of output has been sent before the call.

换句话说,在向用户显示任何内容之前,您的 header() 代码需要位于脚本的开头.如果这仍然不起作用,请确保您的 php 标签之外没有任何空格或其他空格.

In other words, your header() code needs to be at the start of your script, before you display anything to the user. If that still isn't working, make sure you don't have any spaces or other whitespace by mistake outside of your php tags.

这篇关于PHP header() 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆