Question: I have a IN/OUT ratio hit counting system on my site. When a user is sent to my site, I grab the referrer, strip the domain, look up the domain and +1 to hits\_in. Very simple. What I discovered thou is, if a user refreshes the page, the referrer is resent to the site, and it counts it as another +1. Whats even worse is that if user clicks on some link on the site, and then hits BACK to go to the original page, the referrer is resent, and it counts as another +1. So if a foreign site sends me 1 user, who clicks on a video link, views the video, hits BACK in his browser, and then does this 3 times, it will count as if a site sent me 4 users when in fact its just 1.

Any way I could prevent the 2 examples from happening without actually logging all IPs and checking access times for each IP before doing the +1.

Answer: 
I am not expert in this, but can't you just use sessions. temporarily store referred url into session, so if user clicks back than check if users session contains referral site. if it contains don't count.
Here's a referer script i use sometimes.

Put this in your functions file.

```
function referer()
{
    if(isset($_SERVER["HTTP_REFERER"]) && substr($_SERVER["HTTP_REFERER"], 0, 22) != "http://www.example.com" && substr($_SERVER["HTTP_REFERER"], 0, 18) != "http://example.com")
    {
        $result = sprintf("INSERT INTO referer (referer, ip, date) VALUES ('%s', '%s', '%d')", mysql_real_escape_string($_SERVER["HTTP_REFERER"]), mysql_real_escape_string($_SERVER["REMOTE_ADDR"]), time());
        $query = mysql_query($result);

        if($query)
        {
            return true;
        }
        else 
        {
            return false;
        }
    }
}

```

And somewhere in your index file

```
session_start();
if(!isset($_SESSION["referer"]))
{
    if(referer())
    {
        $_SESSION["referer"] = 1;
    }
}

```