Issue with saving referrer info in cookies

Discussion in 'PHP' started by scottatmu, Mar 19, 2008.

  1. #1
    So I'm re-writing a unique visitor tracking system for one of my websites and am having trouble having the script actually hold the referrer(s) info in a cookie. It tracks unique visitors based upon if they have visited my website from a unique website. In other words, if the visitor came to our website from domainA.com, then that would be unique. If the same visitor came to my website from domainB.com, that too would be unique.

    Basically this part grabs the domain name of the referrering website.

          $referral = $_SERVER['HTTP_REFERER'];
    
          if(!empty($referral)){
    
            $refdomain = get_domain_name($referral);
          
          }
    Code (markup):
    Now I check to see if there is a cookie for the specific referrer domain set, and if it isn't, we need to set it.

    if(!isset($_COOKIE['refdomain'][$refdomain])){
                
                $midnight = strtotime("tomorrow 00:00");
                
                $now = time();
               
                $deletetime = $midnight-$now;
    
                setcookie("refdomain[$refdomain]","$now",$midnight);
    
                $_SESSION['refdomain']=$refdomain;
                
                       
              }
    Code (markup):
    So far so good?

    The problem I'm running into is that the only way for it to HOLD the cookie is to then do a header redirect. If I don't do a header redirect, then when the person refreshes or goes to another page of my website, the cookie is not saved.

    Any suggestions?
     
    scottatmu, Mar 19, 2008 IP
  2. scottatmu

    scottatmu Well-Known Member

    Messages:
    311
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    130
    #2
    Found the solution. Kept forgetting to set the path in the cookie.
     
    scottatmu, Mar 19, 2008 IP