#native_company# #native_desc#
#native_cta#

Click tracking script

By david earley
on April 26, 2008

Version: 2.0.0

Type: Full Script

Category: Other

License: GNU General Public License

Description: Allows you yo monitor how many times a link/image/banner is clicked, also allows you to diguise affiliate links. Consists of 1 small PHP file and is very easy to use.

<!-- Mysql


CREATE TABLE `click` (
  `id` varchar(50) NOT NULL,
  `url` varchar(75) NOT NULL,
  `hits` varchar(50) NOT NULL,
  `date` date NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


-->



<title>Click Tracking</title>
<hr />
<form id="form1" name="form1" method="post" action="click.php">
  <table width="457" border="0" align="center">
    <tr>
      <td width="130">Destination Url </td>
      <td width="182"><label>
        <input name="url" type="text" id="url" value="http://" size="50" />
        </label></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><label>
        <input type="submit" name="button" id="button" value="Submit" />
        </label></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><a href="click.php?fn=stats">Click here for stats</a></td>
    </tr>
  </table>
  <div align="center"></div>
</form>
<hr />
<p>&nbsp;</p>
<p>
  <?php
  
//////////////////////////////////////////////////////////////////
//
//         Click tracking script
//         Created by Dave E - david4ie [at] yahoo.com v2.0.
//
//////////////////////////////////////////////////////////////////

$mysql_db = "click";
$mysql_u = "root";
$mysql_p =  "" ; 

function connect ($mysql_db, $mysql_u, $mysql_p)
{

MYSQL_CONNECT("localhost","$mysql_u","$mysql_p");
mysql_select_db("$mysql_db");

}

$id_url = $_GET['id'];
$fn = $_GET['fn'];
$url = $_POST['url'];
$submit = $_POST['button'];
$hits = "0";
$date = date("d.m.y");




switch ($fn) {
case "click":
////////// Function: Click ////////////
connect ($mysql_db, $mysql_u, $mysql_p);


$query1  = "SELECT url FROM click WHERE id = "$id_url" ";
$result1 = mysql_query($query1);


  mysql_query("UPDATE click SET hits=hits+1
  WHERE id = '$id_url'");


while ($row = mysql_fetch_row($result1))
{

$r = $row['0'];

header("Location: $r");
}

////////// End Function: Click ////////////
    break;
case "stats":
$mysql_db = "click"; ////////// The name of the database you are using
$mysql_u = "root"; /////////// Your mysql user name
$mysql_p =  "" ; ///////////your mysql password

connect ($mysql_db, $mysql_u, $mysql_p);

$result = mysql_query("SELECT id, url, date, hits FROM click") 
or die(mysql_error());  

echo "<table border='1'>";
echo "  <tr>
    <td>Id</td>
    <td>Url<br>Tracking url</td>
    <td>Date added</td>
    <td>Hits</td>
	<td>Delete</td>
	
  </tr>";

while($row = mysql_fetch_array( $result )) {
	echo "  <tr>
    <td>"; echo $row['id']; echo "</td>
    <td>"; echo $row['url']; echo "<br> <a href="click.php?fn=click&id="; echo $row['id']; echo "">click.php?fn=click&id="; echo $row['id']; echo "</a></td>
    <td>"; echo $row['date']; echo "</td>
    <td>"; echo $row['hits']; echo "</td>
	<td><a href="click.php?fn=del&idd="; echo $row['id']; echo "">Delete</a></td>
	
  </tr>"; 
	
} 

echo "</table>";
    break;
	case"del":
	
	connect ($mysql_db, $mysql_u, $mysql_p);
	$idd = $_GET['idd'];
	
	$result=mysql_query("DELETE FROM click WHERE id="$idd"");
	
	$mysql_db = "click"; ////////// The name of the database you are using
$mysql_u = "root"; /////////// Your mysql user name
$mysql_p =  "" ; ///////////your mysql password


$result2 = mysql_query("SELECT id, url, date, hits FROM click") 
or die(mysql_error());  

echo "<table border='1'>";
echo "  <tr>
    <td>Id</td>
    <td>Url<br>Tracking url</td>
    <td>Date added</td>
    <td>Hits</td>
	<td>Delete</td>
	
  </tr>";

while($row = mysql_fetch_array( $result2 )) {
	echo "  <tr>
    <td>"; echo $row['id']; echo "</td>
    <td>"; echo $row['url']; echo "<br> <a href="click.php?fn=click&id="; echo $row['id']; echo "">click.php?fn=click&id="; echo $row['id']; echo "</a></td>
    <td>"; echo $row['date']; echo "</td>
    <td>"; echo $row['hits']; echo "</td>
	<td><a href="click.php?fn=del&idd="; echo $row['id']; echo "">Delete</a></td>
	
  </tr>"; 
	
} 

echo "</table>";
	break;
	
}



if ( isset ($submit))
{

connect ($mysql_db, $mysql_u, $mysql_p);

// Generate id ///
$id1 = mysql_query("SELECT * FROM click");
$id2 = mysql_num_rows($id1);
$id = ($id2 + 1);

$result=MYSQL_QUERY("INSERT INTO click (id,url,hits,date) ".
        "VALUES ('$id','$url','$hits','$date')");

 	if($result)
	{
	
	$u = $_SERVER['PHP_SELF'];
		print "<p><strong><font color="#CCCCCC">You have succesfully created a new link, Below is the tracking URL </font></strong></p><br><br><hr><br>http://{your URL}/click.php?id=$id&fn=click<hr><br>";
	}
	else
	{
		print "Error - There has been an error, please make sure config is correct";
	}
			
    MYSQL_CLOSE();


}

?>