Hi everyone. I am currently using a script that counts the clicks from outside users. For example a user clicks a link (lets say click.php?=1) which loads checks there ip address (which ip addresses in the database) if its not in the database add there ip address to the database and add a +1 to the link count for that link. But say you have a different link say click.php?id=2 but this one goes to a totally different website if the same user clicks that link the script checks if the ip is in the database but because the user clicked it before using click.php?=1 it doesnt add a +1 for click.php?=2 i was wondering how i can make it so if someone clicks click.php?id=1 it will add a +1 for that link and also if they click.php?id=2 i will add a +1 for that link aswell but only if they not clicked each link before. Can some please help me with this? The current code i am using is below:
<?php
$host = 'l';
$user = '';
$pass = ';
$db = '';
mysql_connect($host,$user,$pass) or die (mysql_error()); // try to connect to database
mysql_select_db($db); // try to select the database with the link details
$id = stripslashes($_GET['id']);
if(!$id)
exit; // if the link was not specified, stop runing
$id = stripslashes($id); // for security reasons
$linkquery = mysql_query("SELECT * FROM links WHERE id=$id LIMIT 1;"); // look for the specified link
$link = mysql_fetch_array($linkquery);
if(!$link)
die("The specified ID does not exists!");
// if the ID exists in the database, start the count process
$day = date("d");
$month = date("m");
$year = date("y");
$date = "$day/$month/$year";
$ip = $_SERVER["REMOTE_ADDR"];
$query = mysql_query("SELECT * FROM links_info WHERE ip='$ip';");
$lookvisitorsip = mysql_fetch_array($query);
if(!$lookvisitorsip) // if the visitor's ip isn't already in the database add one more click
mysql_query("UPDATE links SET clicks=(clicks+1) WHERE id=$id;"); // add 1 click to the specified id
// if you just want to count clicks, without get members info delete this next line
mysql_query("INSERT INTO links_info (id,ip,date) VALUES ($id,'$ip','$date');") or die(mysql_error()); // save the area which your visitor went, their IP and the date when they visit it
header("Location: $link[ref]"); // redirect to the page//
//echo "Link:".$link[ref];
?>
Also can some please let me know if this code is secure? Is there something i can add to this code so it checks which id an ip address came from so it will work with differrent links and still allow different people to click?
Thanks