May 15, 2007

PHP and JavaScript Cookie

Thanks for visiting.

6 Comments:

lahlah said...

Is it possible to save and get cookies via javascript inside a Blogger blog?

Satya Prakash Karan said...

If it is possible to add your javascript code and javascript file then it should be possible doing that also.
I never tried that.

lahlah said...

It doesn't work with me. :(
All the javascript works fine, except for the set cookie part.
When I check browser's cookies for my blogger blog only the Google Analytics cookies are saved.

Satya Prakash Karan said...

Are you setting the cookie correctly. Here in blogspot is a sub domain concept.

Deaddancer said...

I have been grappling with a way to get a variable from javascript to PHP and finally gave cookies a try. I have a confirm pop up in my js, and based on what they click (OK/Cancel) I either set a cookie (load_all_data=Y) or I delete it. Then back in my PHP I do a comparison operation;
(if ($_COOKIE["load_all_data"]=='Y')

and it ALMOST works perfectly. The issue seems to be that when I process this PHP code, the cookie value is always one step behind, as if PHP reads the value of the cookie before it's assigned. Does this make sense? Basically, my confirm message logic works flawlessly the 2nd time you click one of the options, but as soon as you change to the other option, it doesn't work until you do it once more, and vice versa when switching back (i.e. OK vs. Cancel)

Satya Prakash Karan said...

yes, cookie will be accessed lately. it will be late by one step!

 
Privacy Policies
Blogroll