woff 發表於 2017-11-8 13:46:44

PHP 5.4 setcookie headers already sent by setcookie 問題

今天在測試PHP時
源碼
<?php
$RPage = $_GET['RPage'];
$RID = $_COOKIE["RID"];
if (!isset($_COOKIE['RID'])){
                setcookie('RID',addslashes($_GET['RID']),time()+2*60*60);
}
      
$Click_ID = $_COOKIE['Click_ID'];
      if (!isset($_COOKIE['Click_ID'])){
                setcookie('Click_ID',addslashes($_GET['Click_ID']),time()+2*60*60);
}
$RPath = $_SERVER['HTTP_HOST']."/".$RPage;

if($RPage)
header("Location: ".$RPath);
else
header("Location: ".$_SERVER['HTTP_HOST']);

?>

結果輸出
cannot modify header information - headers already sent by setcookie可是這頁面根本沒輸出阿
怎麼會這樣

請教古歌大神

I also encountered this exact problem and finally found a solution. You have to save the file without the utf-8 BOM signature since that includes a character at the top of the document.In adobe dreamviewer I just had to uncheck the "Include Unicode Signature (BOM)" when saving the file and my problem was solved.您必須保存沒有utf-8 BOM簽名的文件,因為在文檔頂部包含一個字符。

在Adobe DreamWaver中,在保存文件時取消選中“包括Unicode簽名(BOM)”,問題就解決了。
https://stackoverflow.com/questions/8311129/php-setcookie-gives-cannot-modify-header-information-headers-already-sent
頁: [1]
查看完整版本: PHP 5.4 setcookie headers already sent by setcookie 問題