PDA

View Full Version : Hit counter for links....


imk
07-08-2007, 04:23 PM
is there a modification or can somone find or suggest a way to do this,

i want to start up a rap directory and want to have profiles on rap sites....so i want a counter that will count the amount of clicks going from my site to each other rap site...anyone?

????????????

Andrew Green
07-10-2007, 02:13 PM
quick and dirty version:

Setup a table in your database:


create table linklog (linklogid integer not null auto_increment primary key, name text, link text, description text)


Create a file to log and redirect clicks:

link.php

<?php

if($_GET['goto'])
{
require_once('./global.php');
global $db;

$goto = $_GET['goto'];

$db->query("UPDATE linklog SET linkcount=linkcount+1 WHERE link='$goto'");

header("Location: $goto");
}
?>



then instead of linking to "http://google.com", link to "link.php?goto=http://google.com"

To pull a count out of the database:

In your directory file you would do something like this:


$output = "";
$linklist = $db->query_read("SELECT * FROM linklog");
while($link = $linklist)
{
$url = $link['link'];
$count = $link['linkcount'];
$description = $link['description'];
$name = $link['name'];
$output .= "<p><a href='$url'>$name</a> ($count) - $description</p>";
}