Jump to content
dalawh

Cookies

Recommended Posts

I notice that you can check if a cookie is set or retrieve the information if you knew the name, but what happens if the name was dynamic (changing for each person)? Is there no way to retrieve it? Should the name always be dynamic?

Share this post


Link to post
Share on other sites

The $_COOKIE array is a normal array, so you can loop through it with a foreach loop to get the keys or use a function like array_keys to return an array of all of the keys, which will correspond to cookie names. http://www.php.net/manual/en/function.array-keys.php

Share this post


Link to post
Share on other sites
The $_COOKIE array is a normal array, so you can loop through it with a foreach loop to get the keys or use a function like array_keys to return an array of all of the keys, which will correspond to cookie names. http://www.php.net/m....array-keys.php
I just realized something... since the $_COOKIE array is a normal array, instead of using the names, couldn't I just use $_COOKIE[0] to get the value of the name. I know this is less accurate, but isn't that a possibility. Also, thanks for informing me of the array_keys.

Share this post


Link to post
Share on other sites

That won't work, in that case 0 is the key. That would only be true if you had a cookie with a name of "0".

Share this post


Link to post
Share on other sites
That won't work, in that case 0 is the key. That would only be true if you had a cookie with a name of "0".
So the $_COOKIE array does not go by numeric index? Edited by dalawh

Share this post


Link to post
Share on other sites

Like $_GET, $_POST, and $_FILES, the $_COOKIE array is an associative array where the keys are the names of the elements.

Share this post


Link to post
Share on other sites
Like $_GET, $_POST, and $_FILES, the $_COOKIE array is an associative array where the keys are the names of the elements.
Oh okay. Thanks a lot.

Share this post


Link to post
Share on other sites
Guest So Called
I notice that you can check if a cookie is set or retrieve the information if you knew the name, but what happens if the name was dynamic (changing for each person)? Is there no way to retrieve it? Should the name always be dynamic?
I think it's excessive to give different users different cookie names, particularly when you can load up the contents with almost unlimited encryption schemes, and can use multiple cookies. I've spent a fair amount of time looking at the cookies stored on my computer and I've never noticed any sites that use different cookie names between users. (I've been admin on various forum sites, and wrote forum software for a while, so I've created multiple accounts for testing and I've looked at the code for at least one flavor forum software.) I don't see anything to be gained by giving different people different cookie names. The KISS principle says things should be no more complicated than they need be. Anything more complicated just takes more coding time, more debug time, and takes more labor if it needs to be maintained later.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...