我最近在我的电脑上安装了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
答案 0 :(得分:0)
有一个错字,你忘了双引号:
header("location:".SITE."index.php?page=inventory_sub_categoryfrm);
// here ---^
Cookie生命周期太短,使用time()+5
给你5秒钟,所以请延长使用寿命time()+86400
。