看板 PHP 關於我們 聯絡資訊
根據我的經驗會出現「modify header」 的原因如下 1.在setcookie之前有先echo 等印出動作 2.在setcookie之前的變數給值有多空格, ex: $yan="test";__←這邊多空格 __ ↑這邊多Enter 所以先檢查是否有做輸出的總作,再來就是檢查是否有多餘的"空格" ※ 引述《misatocat (天使級廢材!)》之銘言: : 對於 php 我還算個新手,所以想請問一下各位大大 : 我想利用一組亂數來當做使用者的ID : 下以,是我的程式碼 : if (!isset($id)) { : srand((double)microtime()*1000000); : $id = rand(); : setcookie("id",$id,time()+14400,"/",".domain.name",0); : } : 不過,這樣設置,都會在 setcookie那邊出現編碼錯誤 : Warning: Cannot modify header information - headers already sent by (output started at /home/test/public_html/index.php:6) : in /home/test/public_html/index.php on line 20 : 換了一些方式 ,總是會在setcookie那邊出錯 : 真的很傷腦筋............ㄒ又ㄒ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.66.21.31