dalawh Posted June 5, 2012 Share Posted June 5, 2012 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? Link to comment Share on other sites More sharing options...
justsomeguy Posted June 5, 2012 Share Posted June 5, 2012 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 Link to comment Share on other sites More sharing options...
dalawh Posted June 5, 2012 Author Share Posted June 5, 2012 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. Link to comment Share on other sites More sharing options...
justsomeguy Posted June 5, 2012 Share Posted June 5, 2012 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". Link to comment Share on other sites More sharing options...
dalawh Posted June 6, 2012 Author Share Posted June 6, 2012 (edited) 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 June 6, 2012 by dalawh Link to comment Share on other sites More sharing options...
justsomeguy Posted June 6, 2012 Share Posted June 6, 2012 Like $_GET, $_POST, and $_FILES, the $_COOKIE array is an associative array where the keys are the names of the elements. Link to comment Share on other sites More sharing options...
dalawh Posted June 6, 2012 Author Share Posted June 6, 2012 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. Link to comment Share on other sites More sharing options...
Guest So Called Posted June 6, 2012 Share Posted June 6, 2012 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. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now