php - Unable to access cookie after page redirect -
i setting cookie containing vlue in format , redirecting page via php header function. here's code,
setcookie("mycookie", $cookievalue, time() + $cookielife, "/"); // cookielife expiration time in sec header("location: $baseurl/index.php"); // $baseurl "http://localhost/mysite"
the cookie getting set within browser. however, unable access cookie value in redirected page, i.e., "index.php". trying access cookie value simple echo this,
echo $_cookie['mycookie'];
however instead of cookie value, following notice,
notice: undefined index: mycookie in /path/to/my/site/index.php on line 1
i have set cookie path "/" after looking @ other solutions still unable solve this.
any appreciated.
edit : testing on xampp server, , "mysite" here alias location on hard drive. causing issue?
i assume cookie gets removed or dissapears once you've left previous page.
check if
time() + $cookielife
desired time want cookie live. php setcookie function tells me$cookielife
time in seconds want cookie live, make sure it's value want be.use extension check current cookies (and alter them if need to). way can check , make sure if cookie living long want (you mentioned seeing cookie being set, include in case + future visitors).
firefox extension: web developer
chrome extension: cookies
Comments
Post a Comment