这样的异常有人会弄好吗
时间:2021-07-01 10:21:17
帮助过:3人阅读
这样的错误有人会弄好吗?
错误提示是:
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /www/web/jiayiblog_com/public_html/buy.php:2) in /www/web/jiayiblog_com/public_html/buy.php on line 2
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /www/web/jiayiblog_com/public_html/buy.php:2) in /www/web/jiayiblog_com/public_html/buy.php on line 2
Warning: Cannot modify header information - headers already sent by (output started at /www/web/jiayiblog_com/public_html/buy.php:2) in /www/web/jiayiblog_com/public_html/buy.php on line 58
错误就是这样,而buy.php的代码是:
ob_start();
$parray = $_SESSION["mycar"];
?>
include_once("functions/databaseconnection.php");
$arr=array();
$name=$_GET["name"];
$con = "select * from allproduct where name='$name'";
getConnection();
$result=mysql_query($con);
while($result1=mysql_fetch_array($result)){
$arr[]=$result1;
}
$pname = $arr[0]['name'];
$pprice = $arr[0]['price'];
$pfare = $arr[0]['fare'];
$id = $arr[0]['id'];
if($id==""){
if(!is_array($parray)){
echo("你的购物车没有商品");
}
else{
header("location:car.php");
}
}
else{
if(is_array($parray)){
if(array_key_exists($id,$parray)){
$uu = $parray[$id];
$uu["num"] = $uu["num"]+1;
$parray[$id] = $uu;
}
else{
$parray[$id] = array("id"=>$id,"name"=>$pname,"price"=>$pprice,"fare"=>$pfare,"num"=>1);
}
}
else{
$parray[$id] = array("id"=>$id,"name"=>$pname,"price"=>$pprice,"fare"=>$pfare,"num"=>1);
}
$_SESSION["mycar"] = $parray;
ob_clean();
header("location:car.php");
}
?>
原因是什么呢?麻烦各位帮帮忙,是不是那个session_start的问题呢?麻烦各位了。
------解决方案--------------------
session要在最前面
------解决方案--------------------
session_start放到第一行
------解决方案--------------------
这个有问题:session_start();必须在输出之前
改成这样:
session_start();
?>
------解决方案--------------------
session_start();
之前不能有输出
header也是的
UTF8格式的BOM也不行 要注意
------解决方案--------------------
在程序的第一行前加入
ob_start();