session_start() [function.session-start]:,session
我在學習PHP的,當我嘗試做在session_start() - 擷取有關錯誤資訊不能發送會話cookie。
我看到在這個問題上前面的問題,但是,仍然不能確定我的錯誤。
如果是錯誤傢伙?
<?php
session_start();
if ($_POST['add'])
{
foreach ($_POST['a_qty'] as $k => $v)
{
$_SESSION['cart'][$k] = $_SESSION['cart'][$k] + $v;
}
}
?>
<?php
// look for catalog file
$catalogfile = "catalog.dat";
// file is avaialbe, extract data from it and place into $catalog, with sku as key
if (file_exists($catalogfile))
{
$data = file($catalogfile);
foreach ($data as $line)
{
$lineArray = explode(":", $line);
$sku = trim($lineArray[0]);
$CATALOG[$sku]['desc'] = trim($lineArray[1]);
(www.111cn.net) $CATALOG[$sku]['price'] = trim($lineArray[2]);
}
}
else
{
die("Could not find the catalog file");
}
?>
<table border="1" cellspacing="10">
<?php
// print items from the catalog for selection
foreach ($CATALOG as $k => $v)
{
echo "<tr><td colspan=2 width=750>";
echo "<b>" . $v['desc'] . "</b>";
echo "</td></tr>";
echo "<tr><td>";
echo "Price per unit: " . $CATALOG[$k]['price'];
echo "</td><td>Quantity: ";
echo "<input size=4 type=text name="a_qty[" . $k . "]">";
echo "</td></tr> ";
}
?>
from:http://www.111cn.net/phper/21/2de12f9039ff28ce01ffa0e274bb51f3.htm
代碼這樣寫可以? 網上首頁顯示 Warning: session_start() [functionsession-start]:
要確保session_start();這個函數之前沒有任何輸出,包括頭部輸出,或者把這段代碼去掉,再把php.ini(在\php\目錄下)中的session.auto_start = 0 為 session.auto_start = 1
session_start() [functionsession-start]: Cannot send session cookie - headers already sent by
錯誤提示
Warning: Cannot send session cache limiter - headers already sent
分析及解決辦法
這一類問題,的原因是你在程式中使用session_start()時,之前已經有實際的html內容輸出了。或許你說,我沒有啊,我只不過是echo或
print一條訊息了。很抱歉,你的echo或print語句所產生的輸出,就是實際的html內容輸出。解決此類問題的辦法是,將你的
session_start()調到程式的第一行。