Jump to content

Tracking Referrers


Rheves

Recommended Posts

I want to start tracking referrers to the site, so I've set up a table with  Hits, WebPage, and Referrer. Since every page includes Top.php I'd be including this at the top:

 

$Hits = 0;
$Exists = "No";

$ref=@$HTTP_REFERER;
$query = "Select Hits from WebsiteTraffic where WebPage = '$HTTP_HOST$PHP_SELF' AND Referrer = '$ref' ";
$result = mssql_query($query);
while($row = mssql_fetch_array($result){
  $Hits = $row["Hits"];
  $Hits += 1;
  $query = "UPDATE WebsiteTraffic set Hits = '$Hits' where WebPage = '$HTTP_HOST$PHP_SELF' AND Referrer = '$ref' ";
  $result = mssql_query($query);
  $Exists = "Yes";
}
if($Exists == "No"){
  $query =  "INSERT INTO WebsiteTraffic Values('1','$HTTP_HOST$PHP_SELF','$ref')";
  mssql_query($query);
}

 

I think I've covered everything but I want to get this right from the start, does anyone have any tips or see any problem with what I have there?

Link to comment
https://forums.phpfreaks.com/topic/81330-tracking-referrers/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.