I recently installed centos(linux) on my pc. I have a piece of code in which setcookie function is used for displaying a message. It works perfectly on all other windows pcs connected in a network. I have no clue about what is wrong. Is there need of any additional parameter to be applied in setcookie function for linux?
The code I applied is as follows:
setcookie("msg","This record already exist",time()+5,"/");
header("location:".SITE."index.php?page=inventory_sub_categoryfrm);
exit;
and isset($_COOKIE['msg'])
returns false.
Http header:
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
There is a typo, you forgot a double quote:
header("location:".SITE."index.php?page=inventory_sub_categoryfrm);
// here ---^
Also the cookie lifetime is too short, you're giving it 5 seconds by using time()+5
, so please give it a longer life span time()+86400
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.