php cookie stores wrong post ID
-
Using the following code in the header.php:
global $wp_query; $post_id = $wp_query->post->ID; $cookietime = time()+3600*24*365; setcookie('tst', $post_id, $cookietime, '/', '.domain.com');
Every browser returns the right post id except Firefox (3.6.10 on windows). Firefox first writes the right id of the post, but then overwrites it whit the one published after the one it’s showing. I’ve checked it several ways! In other words, ik I write the post id to a variable and store the variable in a cookie I’ll get two id’s in one pageview. Like so:
global $wp_query; $post_id = $wp_query->post->ID; $cookietime = time()+3600*24*365; $lt = '|' if (isset($_COOKIE['tst'])) { $viewed = $_COOKIE['tst']; $viewedstring = substr($viewed, 0, -1); $viewedstring .= $post_id.$lt; setcookie('tst', $viewedstring, $cookietime, '/', '.domain.com'); }else{ $viewedstring = $post_id.$lt; setcookie('tst', $viewedstring, $cookietime, '/', '.domain.com'); }
returns 421|427| in one pageview.
What’s happening?!
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘php cookie stores wrong post ID’ is closed to new replies.