警告:无法修改标头信息 - 已经发送的标头

Dee*_*wal 1 php

今天我第一次使用cookie但是我正面临警告

警告:无法修改标头信息 - 已在第7行的E:\ xampp\htdocs\home_page.php中发送的标头(输出从E:\ xampp\htdocs\session.php:11开始)

这是我的代码:

<?php
include("session.php");
?>

<?php
$Month = 2592000 + time();    //this adds 30 days to the current time
setcookie(AboutVisit, date("F jS - g:i a"), $Month);
?>

<?php
if(isset($_COOKIE['AboutVisit']))
{
$last = $_COOKIE['AboutVisit'];
echo "Welcome back!  You last visited on ". $last;
}
else
{
echo "Welcome to our site!";
}
?>

<html>
<head>
    <title>Home Page</title>
    <script src="flowplayer-3.1.4.min.js"></script>

</head>


<body bgcolor="white">
<?php include('search_file.php'); ?>
<font color="red"><b><h2 align="center">Deepak Narwal Welcomes You</h2></b></font>
<hr size="2" width="50%">
<a  href="logout_file.php"><h3 align="right">Sign Out</h3></a>

<a 
    style="display:block;width:250px;height:200px;" 
    id="player">
</a>
<script language="JavaScript">
    flowplayer("player", "flowplayer-3.1.5.swf" , { clip: { autoPlay : false, autoBuffering: true},   playlist: [ 'video.flv', 'flowplayer.flv'] });  //create a object of clip name
</script>


<object classid="clsid:67DABFBF-D0AB-41fa-9C46-CC0F21721616" align="right" width="320" height="260" codebase="http://go.divx.com/plugin/DivXBrowserPlugin.cab">
<param name="custommode" value="none" />
    <param name="loop" value="true" />
    <param name="autoPlay" value="false" />
    <param name="autoBuffering" value="true" />
    <param name="src" value="http://localhost/idiot.mkv" />
<embed type="video/divx" src="http://localhost/idiot.mkv" custommode="none" width="250" height="200" loop="true"  autoPlay="false"  pluginspage="http://go.divx.com/plugin/download/">
</embed>
</object>


<br /><a href="upload_file.php"><h4>Up-Load Files</h4></a>
<br /><br />
<a href="list_files.php"><h4>List All Up-Loaded Files</h4></a>



</body>
</html>
Run Code Online (Sandbox Code Playgroud)

这是什么错误,如何隐藏我的网页警告?

是否有任何特定的地方放置cookie或我可以把cookie放在像cookie一样的地方吗?

这是我的session.php

    <?php
    session_start();
    if(!isset($_SESSION['employee']))
    {
        echo "Your are Logged Out";
        exit;
    }   

    else
    {
    echo "Welcome Mr.".$_SESSION['employee']['username'].";
    }
    ?>
Run Code Online (Sandbox Code Playgroud)

Tyl*_*ter 5

因为你有setcookie一堆空格后的命令.又名:

?>
             <--- Whitespace
<?php
Run Code Online (Sandbox Code Playgroud)

你不能发送cookie.

你应该这样做:

<?php
include("session.php");
?>

<?php
$Month = 2592000 + time();    //this adds 30 days to the current time
setcookie(AboutVisit, date("F jS - g:i a"), $Month);
?>
Run Code Online (Sandbox Code Playgroud)

这个:

<?php
include("session.php");

$Month = 2592000 + time();    //this adds 30 days to the current time
setcookie(AboutVisit, date("F jS - g:i a"), $Month);
?>
Run Code Online (Sandbox Code Playgroud)

如果仍然出现此错误,则很可能在session.php中有类似的空格.此外,如果你echo之前有什么setcookie,你会有同样的影响.

'空白'基本上是<?php?>标签之外的任何东西,你不能在一个headersetcookie命令之前拥有任何东西.


为了摆脱警告/错误,你可以设置error_reporting(0).

但是,您应该只在生产阶段(当您将网站放在网上时)执行此操作.您应该对代码进行编程,以便没有错误,即使是error_reporting(E_ALL).

警告是有原因的.不要忽视它们.