Cookies and Arrays -- How to break apart cookies?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
shanejeffery86
Forum Newbie
Posts: 2
Joined: Tue Jul 22, 2008 12:57 pm

Cookies and Arrays -- How to break apart cookies?

Post by shanejeffery86 »

Hey there guys.

I have been trying to figure out how this is to be done, but I am losing the battle here.

This is what I have coded so far:

------------------------------------------------------------------------------------------------

Page One: (User is logged out) -- Javascript page

* You add a "session"(s) to your profile.
* This "session"(s) ID is stored in the cookie.
(When performing an alert on what the cookie holds, this is what is produces: {"sessions":["7713","7708","7714","7717"]} )

Page Two: (User is logged in) -- PHP page

* Cookie data is received via a GETDATA.

-------------------------------------------------------------------------------------------------

What needs to happen on Page Two is the following:

* After the cookie data has been received, it needs to be sanitized (leaving only the numbers and their comma separators).
* After the sanitization, it needs to be broken apart into an array. I suspect that an explode function will work just fine.

After that, I got the rest. I just need to figure out how to best sanitize the data and get it into a functional state.

ALSO: If anyone can recommend a good way for me to check what values the Cookie is getting in the PHP page, it would be greatly appreciated. Obviously, I cannot do a print_r() because that would break the code as this function is not returning a value.

Thanks.
ody3307
Forum Newbie
Posts: 21
Joined: Wed Jul 30, 2008 7:29 am

Re: Cookies and Arrays -- How to break apart cookies?

Post by ody3307 »

I may not be understanding your question properly. If you are trying to find out how to get this information using javascript, I can't help. But, if you want to read the cookie data using php, you will find it in the $_COOKIE array. You can access it like this:

if (isset($_COOKIE)) {
foreach ($_COOKIE as $name => $value) {
echo "$name : $value <br />\n";
}
}

It does not come out pre-formatted, you can do what you want. There is no need to "sanitize".
Post Reply