重複の可能性:
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==ステートメントの1つです。
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」すると、すべてのヘッダーリダイレクトが壊れることです。また、require_once(bamfg_functions.php);を試しました。そして、単にinclude(bamfg_functions.php); 同じ結果になります。
ファイルを呼び出す行をコメントアウトするとすぐに、ヘッダーリダイレクトが機能し、それが私を狂わせます。
ヘッダーリダイレクトは、呼び出される前にブラウザーにデータが出力されていない場合にのみ機能することに気付きましたが、どこにも表示されませんか?
どんなアドバイスも素晴らしいでしょう、ありがとう。