Cookie business
Form time to time, a plugin might have a need to access cookie. So, this little post talks about it.
As suggested by moraes, one should set a cookie in PostAuthentication event if member data is needed. Otherwise, PreSendContentType event is just fine.
To set a cookie:
How and when to access a cookie
The cookie should be accessiable once the HTTP header is sent. That's mean any event after PreSendContentType is fine, which is "Immediately before a content type is being set in the HTTP header".
To access a cookie, simply:
$mycookie = cookieVar('thisCookie');or
$mycookie = $_COOKIE['thisCookie'];How and where to set/update a cookie?
As suggested by moraes, one should set a cookie in PostAuthentication event if member data is needed. Otherwise, PreSendContentType event is just fine.
To set a cookie:
setcookie('sessionStart', $_COOKIE['lastVisit'], 0, $CONF['CookiePath'], $CONF['CookieDomain'], $CONF['CookieSecure']);A discussion is here
Comments
karma wrote:
07/27/04 12:50:52
A little info on the cookieVar function:
cookieVar() is an internal Nucleus function. The advantage of using it in place of $_COOKIE, is that any 'magic' is undone before returning the value. Also $_COOKIE is only available since PHP 4.1.0 (Nucleus is still compatible with 4.0.6)
Undoing the magic is needed on some PHP systems. There's a PHP option called "magic_quotes_gpc". When set to "On", the values in the GET/POST/COOKIE arrays are automatically escaped (e.g. a quote (" gets a slash in front (\" )