Having trouble setting a cookie within wordress.
-
Hi, I hope I have more luck posting the topic here.
My original post states that I’m trying to code a hit counter which counts only unique views to the site. I’m trying to set a cookie with a 1hr expiry.
My code:$file = (TEMPLATEPATH."/count.txt"); $count_unique = 1; $cn = 'gcc'; $count = intval(trim(file_get_contents($file))); if ($count_unique == 0 || !isset($_COOKIE[$cn])) { ++$count; file_put_contents($file, $count); setcookie($cn, '1', time()+3600, '/','.localhost'); } echo $count;
That only works outside of wordpress (excluding the template path constant) so I changed my setCookie accordingly:
setcookie($cn, 1, time()+3600, COOKIEPATH, COOKIE_DOMAIN);
Still no luck. Please help if you know an answer.
Thanks in advance.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Having trouble setting a cookie within wordress.’ is closed to new replies.