簡體   English   中英

setcookie在Linux上不起作用

[英]setcookie doesn't work on linux

我最近在我的電腦上安裝了centos(linux)。 我有一段代碼,其中setcookie函數用於顯示消息。 它可以在網絡中連接的所有其他Windows pc上完美運行。 我不知道怎么了。 是否需要在Linux的setcookie函數中應用任何其他參數?

我應用的代碼如下:

    setcookie("msg","This record already exist",time()+5,"/");
    header("location:".SITE."index.php?page=inventory_sub_categoryfrm);
    exit;

isset($_COOKIE['msg'])返回false。

Http標頭:

    Request URL:http://192.168.1.39/ems/abc.php
    Request Method:GET
    Status Code:200 OK
    Request Headers
    Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
    Accept-Encoding:gzip,deflate,sdch
    Accept-Language:en-US,en;q=0.8
    Cache-Control:max-age=0
    Connection:keep-alive
    Cookie:PHPSESSID=8q10m0jc8c49eneo924udm2093
    Host:192.168.1.39
    User-Agent:Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.31 (KHTML, like Gecko)        

    Chrome/26.0.1410.64 Safari/537.31
    Response Headers
    Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
    Connection:close
    Content-Type:text/html; charset=UTF-8
    Date:Thu, 23 May 2013 10:00:09 GMT
    Expires:Thu, 19 Nov 1981 08:52:00 GMT
    Pragma:no-cache
    Server:Apache/2.2.15 (CentOS)
    Transfer-Encoding:chunked
    X-Powered-By:PHP/5.5.0RC1

有一個錯字,您忘記了雙引號:

header("location:".SITE."index.php?page=inventory_sub_categoryfrm);
//                                                       here ---^

Cookie的壽命也太短,您可以使用time()+5給它5秒鍾,所以請給它更長的壽命time()+86400

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM