php - asking about the cookie after logout -
i'm trying access cookie's value (using $_cookie
) after calling setcookie()
function in php. when so, $_cookie[$cookiename]
isn't set after login. why?
if(isset($_session)){ $_session['email']=$username; $_session['id']=$query['id']; $_session['name']=$query['name']; $_cookie[$cookiename]=$query['name']; $cookiename="user"; $cookie_value = "john doe"; setcookie($cookiename,$cookie_value, time() + (86400 * 30),"/"); if (!$session->check()){ echo $cookiename ; }else { echo $_cookie[$cookiename]; }
this because when call
setcookie()
attaching cookie current response(when current request completes).$_cookie have value when request made cookie header set i.e cookie sent server.
so, when #1 happens don't have in $_cookie, once #2 happens have value in $_cookie
edit: need mentioned in manual http://php.net/manual/en/function.setcookie.php
setcookie() defines cookie sent along rest of http headers once cookies have been set, can accessed on next page load $_cookie array. cookie values may exist in $_request.
Comments
Post a Comment