2012-02-12 28 views
0

我不断收到警告当我尝试和负荷我的网页...掌握Facebook的PHP API“已经发送了头”

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/blazecra/public_html/matt/header.php:23) in /home/blazecra/public_html/matt/facebook/facebook.php on line 37 

这里是我的header.php文件

<?php 
echo '<html> 
<head> 
    <title>MyGag - The Home of Gagging!</title> 
    <link rel="stylesheet" href="style.css" type="text/css" /> 

</head> 
<body> 

    <img src="img/nav.png" height="50" width="1000"> 

<div id="logo"> 
    <a href="index.php"><img src="img/logo.png" height="50" width="150"></a> 
</div> 

'; 
?> 

而且在facebook的第37行php只是有

session_start(); 

任何想法为什么会发生这种情况?

好,所以它的话说,有输出在这个header.php某处我知道im回声ing,但那只是html。

如果你明白我的话,我不会返回任何东西吗?

+0

[接头已经由PHP发送]的可能重复(http://stackoverflow.com/questions/8028957/headers-already-sent-by-php) – mario 2012-02-12 21:22:07

+0

任何输出,其包括的HTML。 – 2012-02-12 21:29:01

回答

3

在完成发送输出后,您不能执行session_start

就像错误说:它不能发送一个cookie,因为已经发送了所有的头文件。无论何时您开始发送数据,都必须(并且将)首先发送标题。

确保在你调用该函数之前没有输出发送给用户。

+0

好的我在哪里输出给用户在这个文件中。我不能看到它 – 2012-02-12 21:26:00

+0

那么,你可以做任何事情?我应该怎么知道,你没有给我完整的代码......但我的猜测是:header.php?它确实在那里说“回声”,不是吗? – Nanne 2012-02-12 21:27:28