我刚刚注册了我的域,一切都很好,但当我在php页面上使用session_start()时,我会收到这个警告
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at D:'inetpub'vhosts'mywebsite.com'httpdocs'sample'new.php:1) in D:'inetpub'vhosts'mywebsite.com'httpdocs'sample'new.php on line 3
`Warning: session_start() [function.session-start]: Cannot send session
cache limiter -
headers already sent (output started at
D:'inetpub'vhosts'mywebsite.com'httpdocs'sample'new.php:1) in
D:'inetpub'vhosts'mywebsite.com'httpdocs'sample'new.php on line 3`
我需要做些什么来消除这个警告我无法在我的php页面上使用session_start()。请帮助我解决这个问题。非常感谢任何帮助。感谢
更新这是我的索引和概要文件.php页面
我的index.php页面
<?php
session_start();
?>
<!doctype HTML> some html coding goes on
我的profile.php页面
<?php
session_start();
$con = mysql_connect('some', 'some', 'some');
$email = $_POST["nemail"];
$password = $_POST["npassword"];
$month = $_POST["nmonth"];
$dayy = $_POST["ndate"];
$yearr = $_POST["nyear"];
$gender = $_POST["ngender"];
$sname = $_POST["sname"];
$status = $_POST["nrelation"];
$rannum = 1;
$birthday = $month . " " . $dayy . " " . $yearr;
mysql_select_db("users_names");
$_SESSION['unique']= $rannum;
?>
当我从index.php 跳转到profile.php时,我会收到这个错误
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at D:'inetpub'vhosts'website.com'httpdocs'sample'profile.php:1) in D:'inetpub'vhosts'website.com'httpdocs'sample'profile.php on line 3
我想在索引页面上启动会话,但我想在profile.php页面中为会话变量赋值,这就是我在最后一行中在profilephp中所做的
您的php脚本是否使用UTF(我的意思是php文件的内容使用unicode编码)?在这种情况下,您删除了BOM记录吗?或者,在打开php标签之前,您可能有空的空间
Wiki
例如,在PHP中,BOM的存在会导致页面在解释初始代码之前开始输出,从而导致问题如果页面试图发送自定义HTTP标头(必须设置在输出开始之前)。
发布代码后会更加简单。
cookie(session_start use cookie)只能与HTTP标头一起发送。如果您已经执行了echo
或在session_start()
函数之前调用了函数headers()
,则不能再发送cookie,因此无法启动会话,因为标头已经发送。
在调用session_start()
之前,确保绝对不输出任何内容,甚至不输出空白。
您需要启用输出缓冲才能使用会话。在php代码的开头使用ob_start()函数