I am setting a cookie in an external JavaScript file with the current user time. I want this time to be available to the server, so I am retrieving this from a cookie.
I am able to fetch the value, but only when I refresh the browser twice. If I change my current system time, and refresh the page, I still see the old time; when I refresh again, then I see the updated time.
JavaScript code
var now=new Date();
currTime=now.getHours();
document.cookie = "currentTime = " +currTime;
PHP code
$current_time = $_COOKIE["currentTime"];
echo $current_time;
I am calling the external JavaScript file in hook_nodeapi() using drupal_add_js().
As I said, I am able to get the updated value of current time from cookie but only if I refresh twice.
What could be the problem?