|
Posted by Rik on 05/15/06 00:32
Bart wrote:
> <script type='text/javascript'>
> <!--
> document.cookie = "qrv=''";
> alert(document.cookie);
> //-->
> </script>
> Later after I call the above function I want to check what is the
> session value
>
> echo $_COOKIE["qrv"];
>
> it is null, but the actual cookie in the browser is set to yes or no.
> When I try again the echo command give me the right output.
>
> Problem is that I always have to refresh the webpage in order to get
> the cookie value.
> It looks like php reads the cookie that was set before you load the
> browser page.
It's the old story:
Javascript runs on the users computer, PHP on the server. PHP sends output
"as is" to the client, with the variables available.
Because the cookie is set AFTER the user has gotten the page, at the time
the page was set this cookie variable wasn't available. No way to "fix"
that, that's just how it works. If you need this functionality, it needs a
different approach. Either create the dynamic content using javascript (for
instance XMLHTTPRequest), or let the user go to a different page.
Grtz,
--
Rik Wasmus
[Back to original message]
|