可能重复:
PHP 中的“警告:标头已发送”
我的 bamfg_functions.php 代码:
<?php
error_reporting(E_ALL & ~E_NOTICE);
define('THIS_SCRIPT', 'test');
define('CSRF_PROTECTION', true);
require_once('global.php');
function bamfg_navigation()
{
global $vbulletin;
if ($vbulletin->userinfo['userid']) {
$navigation .= "<center>- Browse Vehicles - <a href='./bamfg.php'>Search Vehicles</a> -<br>- <a href='./bamfg_vehicle.php'>ADD / EDIT Vehicles</a><br><br> </center>";
}
else {
$navigation .= "<center>- Browse Vehicles - <a href='./bamfg.php'>Search Vehicles</a> -<br><br></center>";
}
return $navigation;
}
?>
这就是我将 bamfg_functions.php 包含到我的 bamfg_vehicle.php 文件中的方式。
require('bamfg_functions.php');
bamfg_navigation = bamfg_navigation();
global $bamfg_navigation;
这是我在 bamfg_vehicle.php 中执行的许多 do== 语句之一。
if($_REQUEST['do'] == 'add_comment') {
$userid = $vbulletin->userinfo['userid'];
$username = $vbulletin->userinfo['username'];
$vbulletin->input->clean_gpc('r', 'id', TYPE_INT);
$vehicle_id = $vbulletin->GPC['id'];
$owner_userid = $_GET["owner_userid"];
// ** THIS GETS THE "POSTED" INFORMATION FROM THE PAGE AND CONVERTS TO VARIABLE - CLEANS INPUT
$vbulletin->input->clean_array_gpc('p', array(
'comment' => TYPE_NOHTML,
));
$comment = $vbulletin->GPC['comment'];
// MAKES SURE THE COMMENT ISN'T BLANK
if (strlen($comment) == 0){
Header( "Location: $website_url/bamfg_vehicle.php?do=view_vehicle& id=$vehicle_id" );
}
else {
$sql = "INSERT INTO ". TABLE_PREFIX ."BAMFG_comment (
comment_id,
vehicle_id,
userid,
owner_userid,
username,
comment) VALUES (
'". $comment_id ."',
'". $vehicle_id ."',
'". $userid ."',
'". $owner_userid ."',
'". $username ."',
'". $comment ."')";
$db->query_write($sql);
Header( "Location: $website_url/bamfg_vehicle.php?do=view_vehicle&id=$vehicle_id" );
}}
我的问题是当我“需要” bamfg_functions.php 文件时,它会破坏我所有的标头重定向,我也尝试过 require_once(bamfg_functions.php); 并且只包括(bamfg_functions.php);结果相同..
一旦我注释掉调用文件的行,标题就会重定向工作,这让我发疯了..
我意识到只有在调用之前没有向浏览器输出数据时,标头重定向才有效,但我在任何地方都看不到?
任何建议都会很棒,谢谢..