first off: I dont know how it was done before d7 so I did not included anything before d7 to this issue.

I really have to vent my anger about cookie handling in drupal. searches for setting cookies showed up the function user_cookie_save()
which works pretty well.

BUT

how the hell are you supposed to figure out how you will be able to retrieve your data?
a function for loading that cookie data? -> no? at least not documented nor used by many of the core modules.
$user->key
-> wrong

so I inspected the cookies themselves - Drupal wrote a cookie in a format like Drupal.visitor.key, so at least the cookie has been set. accessing that cookie turns out to be still a pain in the ass:

for real? $_COOKIE? with some magical detecting how Drupal or whatever formated the cookie value?

$_COOKIE['Drupal_visitor_key']

will do the trick.

this issue took some really valuable hours of my life and I am wondering why theres get or load function for that cookie and why other module developer never complained about this, changed this or at least documented it.

have a good night. maybe a core developer will read this and add a function for that.
meanwhile Ill add a comment to the api page...

Comments

Letharion’s picture

I realize this is old now, but

$_COOKIE is a PHP super global, and is not created by Drupal. As you can see in user_cookie_save() as you linked to yourself, Drupal just lets PHP take care of the cookie, and does no manual handling what so ever of it.

Are there other frameworks that you think handle them better?

I'm not sure what you are suggesting Drupal would do instead?

Why would there be a function for fetching data from an array?

ShawnDevin’s picture

Agreed. Since we have a function user_cookie_save(array('key'=>'value')); to set cookies, and it modifies the cookie key, it would make things simpler for developers if there was a matching function like user_cookie_read('key'); to fetch the value out of the cookie.