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.
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)
6 Comments:
Is it possible to save and get cookies via javascript inside a Blogger blog?
If it is possible to add your javascript code and javascript file then it should be possible doing that also.
I never tried that.
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.
Are you setting the cookie correctly. Here in blogspot is a sub domain concept.
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)
yes, cookie will be accessed lately. it will be late by one step!
Post a Comment