/    Sign up×
Community /Pin to ProfileBookmark

Clearing $HTTP_REFERER on Re-Load

Hello, I’m new to this site and PHP; so hi to everyone.

I have a little problem with $HTTP_RERERER function. I want to track hits in from partner sites using HTTP_REFERER. After spending hours on the script and Google, I have got it to work on the most part. Now what happens is, if someone re-loads the page. It keeps on increasing the hits in from referring partner. I want it to count only the first hit. Here is the code:

<?php
$ref = $_SERVER[‘HTTP_REFERER’];

if(empty($ref)) {
$site = ‘none’;
}
else
{
$site = $_SERVER[‘HTTP_REFERER’];

}
$site = str_replace(“http://”,””, $site);
$site = explode(“/”, $site);
$theSite = $site[0];

$Referers = mysql_query(“SELECT * FROM Links”) or die(mysql_error());
while ($Referer = mysql_fetch_array($Referers)){
$HitCount = $Referer[‘HitsIn’];
$UpdatedHits = $HitCount +1;
if ($Referer[‘lDomain’] == $theSite){
$RefUpdate = “UPDATE Links SET HitsIn=$UpdatedHits WHERE lDomain=’$theSite'”;
mysql_query($RefUpdate);
}
}
?>

I don not want to use another file to redirect E.g. (Hitin.php?ID=10) because this will not increase my Google PR.

Thank you very much for your help.

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@MstrBobJun 23.2006 — Well, the browser will still send the Referrer header when the user reloads the page. Though this is only a problem if the visitor hits refresh. If you are concerned, though, the simplest method would probably be to set a cookie on the user.

[code=php]
<?php
if(!empty($_SERVER['HTTP_REFERER'])&&(empty($_COOKIE['counted'])||$_COOKIE['counted']!='1'))
{
$site = $_SERVER['HTTP_REFERER'];
$site = str_replace("http://","", $site);
$site = explode("/", $site);
$theSite = $site[0];

$Referers = mysql_query("SELECT * FROM Links") or die(mysql_error());
while ($Referer = mysql_fetch_array($Referers))
{
$HitCount = $Referer['HitsIn'];
$UpdatedHits = $HitCount +1;
if ($Referer['lDomain'] == $theSite)
{
$RefUpdate = "UPDATE Links SET HitsIn=$UpdatedHits WHERE lDomain='$theSite'";
mysql_query($RefUpdate);
}
}
setcookie("counted", '1');
}
?>
[/code]
Copy linkTweet thisAlerts:
@jattsurmaauthorJun 24.2006 — Hi Bob,


Thanks a lot you solved my problem. The code works great! It had become a big problem for me. Every time a visitor hits a back button on their browser to go to home page; it would give the partner a hit. Everyday I had to change it manually by looking at my traffic tracking software.

Thanks again for your help. I really appreciate it.


Sincerely,


Jatt Surma
×

Success!

Help @jattsurma spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...