Admun's NUDN

admun

  • San Francisco, CA

Navigation

Navigation

Categories

Cookie business

Form time to time, a plugin might have a need to access cookie. So, this little post talks about it.

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

11:39:57 on 07/02/04 by Admun - Category: Developer Notes - tags: none - print

Comments

karma wrote:

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 (" wink gets a slash in front (\" wink )

07/27/04 12:50:52

Add Comments