Code:
<?
 $db = mysql_connect("server","username","password");
 mysql_select_db("db");
 $updated = mysql_query("UPDATE `links` SET `hits`=`hits+1;");
 if(!$updated) {
  mysql_query("INSERT INTO `links` (`hits`,`url`) VALUES ('1','".$HTTP_GET_VARS["target"]."')");
 }
 mysql_close();
 header("Location: " . $HTTP_GET_VARS["target"]);
?>
That is one way to go about things... but that doesn't do hits so.. scrap that here. use the following.

link.php
Code:
 $db = mysql_connect("server","username","password");
 mysql_select_db("db");
 mysql_query("INSERT INTO `links` (`url`,`ip`,`time`,`referer`,`browser`) VALUES ('".addslashes($HTTP_GET_VARS["target"])."', '".$_SERVER["REMOTE_ADDR"]."', '".time()."', '".$HTTP_REFERER."', '".$HTTP_USER_AGENT."')");
 }
 mysql_close();
 header("Location: " . $HTTP_GET_VARS["target"]);
?>
viewhits.php
Code:
 $db = mysql_connect("server","username","password");
 mysql_select_db("db");
 $hits = mysql_query("SELECT `url` FROM `hits` GROUP BY `url`");
 echo("UGN linked to: ".mysql_num_rows($hits)." different web site(s).
\n");
 while($hit = mysql_fetch_array($hits)) {
  $url = mysql_query("SELECT * FROM `hits` WHERE `url`='".$hits["url"]."'");
  while($page = mysql_fetch_array($url)) {
   echo("url: ".$page["url"].", was visited by: ".$page["ip"].", at: ".date("h:i.a m/j/Y", $page["time"]).", using: ".$page["browser"]."; they came from: ".$page["referer"].".
\n");
  }
 }
 mysql_close();
?>
heres a mysql table for you...

Code:
CREATE TABLE `hits` (
`url` TEXT NOT NULL ,
`ip` VARCHAR( 15 ) NOT NULL ,
`time` INT UNSIGNED NOT NULL ,
`referer` TEXT NOT NULL ,
`browser` TEXT NOT NULL ,
FULLTEXT (
`url` ,
`referer` ,
`browser` 
)
) TYPE = MYISAM COMMENT = 'some hittage';
uhh, Talk to me if you wanan figure out how to do shit like... Tell how many people are using Mozilla Firebird or something.