找回密碼
 註冊
搜索
查看: 1757|回復: 0

[問題] PHP 5.4 setcookie headers already sent by setcookie 問題

[複製鏈接]
發表於 2017-11-8 13:46:44 | 顯示全部樓層 |閱讀模式
 
Push to Facebook
今天在測試PHP時
源碼
  1. <?php
  2. $RPage = $_GET['RPage'];
  3. $RID = $_COOKIE["RID"];
  4. if (!isset($_COOKIE['RID'])){
  5.                 setcookie('RID',addslashes($_GET['RID']),time()+2*60*60);
  6. }
  7.         
  8. $Click_ID = $_COOKIE['Click_ID'];
  9.         if (!isset($_COOKIE['Click_ID'])){
  10.                 setcookie('Click_ID',addslashes($_GET['Click_ID']),time()+2*60*60);
  11. }
  12. $RPath = $_SERVER['HTTP_HOST']."/".$RPage;

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

  17. ?>
複製代碼


結果輸出
  1. 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/questi ... eaders-already-sent
 
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

Archiver|手機版|小黑屋|TShopping

GMT+8, 2025-4-30 21:32 , Processed in 0.020739 second(s), 21 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回復 返回頂部 返回列表