PHP header() does not work(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() 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PHP header() 不起作用
基础教程推荐
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 如何替换eregi() 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
