PHP:头不会重定向
当我把我的网站上线时,所有的标题都不起作用。但当我在本地数据库等上建立它时,它工作得“很好” 我当前在网站上发现此错误: 警告:无法修改标题信息-标题已由第16行的/customers/5/8/4/infuze.dk/httpd.www/index.php:22中的/customers/5/8/4/infuze.dk/httpd.www/includes/functions.php发送 我使用了一点GoogleFoo,据我所知,在使用标题之前,我不能输出任何数据。但我不认为这里是这样 这是我在网站上使用的代码PHP:头不会重定向,php,redirect,header,web,Php,Redirect,Header,Web,当我把我的网站上线时,所有的标题都不起作用。但当我在本地数据库等上建立它时,它工作得“很好” 我当前在网站上发现此错误: 警告:无法修改标题信息-标题已由第16行的/customers/5/8/4/infuze.dk/httpd.www/index.php:22中的/customers/5/8/4/infuze.dk/httpd.www/includes/functions.php发送 我使用了一点GoogleFoo,据我所知,在使用标题之前,我不能输出任何数据。但我不认为这里是这样 这是我在网
if(empty($_GET['page'])){
header('location: index.php?page=homepage');
}
或者至少有一个示例,当您试图重定向的页面包含信息时,我通常会收到错误“无法修改标题信息-标题已由发送人发送”。检查脚本是否使用echo、include、require等,或者在尝试重定向的行之前是否包含HTML标记
<p>Hello!</p>
<?php
header('location: index.php?page=homepage');
?>
<?php
echo "Hi!";
header('location: index.php?page=homepage');
?>
<?php
header('location: index.php?page=homepage');
include('setup.txt');
?>
<h1>Amazing page!</h1>
你好
将不起作用,因为它会在尝试重定向之前发送浏览器信息
<p>Hello!</p>
<?php
header('location: index.php?page=homepage');
?>
<?php
echo "Hi!";
header('location: index.php?page=homepage');
?>
<?php
header('location: index.php?page=homepage');
include('setup.txt');
?>
<h1>Amazing page!</h1>
也不起作用,因为它在尝试重定向之前也会发送浏览器信息
<p>Hello!</p>
<?php
header('location: index.php?page=homepage');
?>
<?php
echo "Hi!";
header('location: index.php?page=homepage');
?>
<?php
header('location: index.php?page=homepage');
include('setup.txt');
?>
<h1>Amazing page!</h1>
太棒了!
将起作用,因为它尝试在重定向后发送浏览器信息,但不会在重定向前发送。在以下情况下,标头不会重定向: 文件中
?>
标记后剩余的任何空格
为了避免这种情况,请避免结束?>
标记(文件结束)
请检查任何echo
或print
语句是否意外写入
另外,请检查是否还有HTML
标记
如果您遵循所有这些,您的脚本将起作用
最后,在文件的开头,将
ob\u start()
此函数将所有页面输出存储在缓冲区中,因此重定向将正常工作。尝试此功能
<?php
ob_start();
// code
ob_end_flush();
?>
>> Call ob_start() at start of the script.
>> call ob_end_flush() at the end of script.
>>在脚本开头调用ob_start()。
>>在脚本末尾调用ob_end_flush()。
谢谢
输出开始于
index.php
行22
您的错误消息逐字说明了检查的位置!!!