I could try.
I didn't make any notes, and this is a complete hack! Maybe you could help me clean it up? I looks like it works on my site, so I'm happy.
It also keeps a track of the clicks to stop cheating :flex:
Database:
CREATE TABLE `links_clicks` ( `site_id` int(11) NOT NULL, `click_time` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, `ip_adr` varchar(30) NOT NULL, KEY `site_id` (`site_id`) ) ENGINE=MyISAM;
header file:
elseif (isset($_GET['links_url'])) {
if (get_magic_quotes_gpc()) $_GET['links_url'] = stripslashes($_GET['links_url']);
$links_url = 'http://'.mysql_real_escape_string($_GET['links_url']);
zen_update_links_click_count($links_url);
}
Functions:
//REMOVE HTTPS
function remove_http($url = '')
{
return(str_replace(array('http://','https://'), '', $url));
}
// Return the links url
function zen_get_links_url($identifier) {
global $db;
$link = $db->Execute("select links_id, links_url from " . TABLE_LINKS . " where links_id = '" . (int)$identifier . "'");
$url = remove_http($link->fields['links_url']);
$links_string = 'links?links_url='.$url;
return $links_string;
}
////
function zen_update_links_click_count($links_url) {
global $db;
$url = 'http://www.yoursite.com';
$result = $db->Execute("select links_id, links_url from " . TABLE_LINKS . " where links_url = '" . $links_url . "'");
if ($result->RecordCount() == 1) {
$url = $links_url;
$id = $result ->fields['links_id'];
$IP = mysql_real_escape_string($_SERVER['REMOTE_ADDR']);
$time_diff = 3600*24*14;
$test = $db->Execute("select COUNT(*) AS testval from " . TABLE_LINKS_CLICKS . " where ip_adr = '".$IP."' AND click_time+".$time_diff." > NOW() AND site_id = '".$id."'");
if ($test->fields['testval'] == 0) {
$db->Execute("INSERT INTO " . TABLE_LINKS_CLICKS . " set ip_adr = '".$IP."', site_id = '".(int)$id."' ");
$db->Execute("update " . TABLE_LINKS . " set links_clicked = links_clicked + 1 where links_id = '" . (int)$id . "'");
}
}
header("Location: $url");
exit;
}
define tag:
define('TABLE_LINKS_CLICKS', DB_PREFIX . 'links_clicks');