Click out tracking ( PHP EXAMPLE )

gptsven

New Member
Messages
253
Reaction score
5
Points
0
Heres an example to track what links get clicked on your website! ( simple script, needs php & mysql )


You need this table :

Code:
DROP TABLE IF EXISTS `traffic_exploit`;
CREATE TABLE `traffic_exploit` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `date` datetime DEFAULT NULL,
  `url` varchar(555) DEFAULT NULL,
  `referer` varchar(555) DEFAULT NULL,
  `ip` varchar(15) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=7 DEFAULT CHARSET=latin1;
its a table with an ID, a date ( when user clicked the link, can later be used to build graphical charts on date) url ( the clicked url, ) referer ( the referring url ) and ofcourse the IP.


The tracking script : track.php
PHP:
<?php
if (isset($_GET['url']))
{
 mysql_connect("localhost","root","");
 mysql_selectdb("traffic****");
 $url = mysql_escape_string($_GET['url']);
 $ip = $_SERVER['REMOTE_ADDR'];
 $referer = $_SERVER['HTTP_REFERER'];
 $query = "INSERT INTO traffic_exploit (ip,date,url,referer)  VALUES ('$ip',now(),'$url','$referer')";
 mysql_query($query);
 header("location:$url");
}
?>

an url gets called like this :
PHP:
<a href="track.php?url=good-traffic-exchange-websites.php" target="_blank" style="color:#375468;">Good Traffic exchange sites</a>
this is the example for an inbound link, for outbound links use this :
PHP:
<a href="track.php?url=http%3A%2F%2Fwww.trafficexploit.co.cc" target="_blank" style="font-size:12px;color:blue;margin-left:0px;">traffic exploit</a>

Heres my example site using this script : http://www.trafficexploit.co.cc
 
Last edited:

lemon-tree

x10 Minion
Community Support
Messages
1,420
Reaction score
46
Points
48
As a matter of fact, your script is wide open to injection through the unescaped referrer variable. Ideally, you should move this over to either PDO or MySQLi, as both offer better alternatives than the mysql_escape_string() function and also because the mysql driver is now twice outdated. Also MySQL offers a better alternative to storing the IP as a string with the INET_ATON() and INET_NTOA() functions.
 
Last edited:
Top