Setting Cookie via PHP works in Chrome but not Firefox or IE


Staff member
I have an issue where setting a cookie works perfectly in chrome but not IE or firefox. All the browsers are the current version and I am on a Windows 8 machine. I am trying to set a cookie which lasts for a year.

I can verify that IE and firefox are receiving other cookies from my site created by other plugins and 3rd party services but it just does not want to accept the cookie I am trying to set.

Via firebug in Firefox, I tried to view rejected cookies but none are listed and it is like my cookie just does not want to work outside of chrome.

This code is in a functions.php file inside of my wordpress website:

add_action( 'init', 'visitor_cookie');
function visitor_cookie() {
    if (!isset($_COOKIE['returning_visit'])) {
        $traffic_type = 'hd';
        $timestring = microtime();
        $pieces = explode(" ", substr($timestring, 2));
        $pieces[0] = "1".substr($pieces[0],0,3);
        $visitor_id = $traffic_type.dechex($pieces[1]) . dechex($pieces[0]);
        $expire = time()+60*60*24*360;
        $path = '/';
        $domain = parse_url(get_option('siteurl'), PHP_URL_HOST);


<li>As a note my domain is currently which will be moved to</li>
<li>This is not on a localhost/server, its at a hosting company</li>
<li>This cookie should be available across my entire website.</li>
<li>Cookie expiration date is set to one year</li>

In addition to viewing the cookies in my browser, I was also using this code to verify the cookie which again showed output in chrome but no other browser.

&lt;?php echo "'".$_COOKIE['returning_visit']."'"; ?&gt;


The issue is the cookie is only set when logged in as admin. The cookie is indeed being set. I created a question more specific to wordpress:

<li><a href=""></a></li>


The issue was my host caching the pages. Needed to uncache the pages for the proper php code to run. Caching was disabled for Admins, which is why I got the cookie as admin and not a normal user.