Page 1 of 1

IP Showing Help

Posted: Mon Mar 17, 2008 8:28 pm
by IT-Guy
Hey,

Below I have put my script up, what it does is: It shows the users their IP Address, and the date, and what visitor number they are.
What Im requesting help with is; what would I like to add to this script that is say you visit the site, and your visitor 54, and you click that 'overview link' the visitor number changes and now you are now visitor '55' if their IP address is the same, I dont want the visitor number to keep going up. If its the same - so if anyone could add to my script to help me out, or give me any tips to help me out that would be great! Thanks

Code: Select all

<?php
$host="***"; // Host name 
$username="**"; // Mysql username 
$password="**"; // Mysql password 
$db_name="**"; // Database name 
$tbl_name="counter"; // Table name 
 
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect to server "); 
mysql_select_db("$db_name")or die("cannot select DB");
 
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
 
$rows=mysql_fetch_array($result);
$counter=$rows['counter'];
 
// if have no counter value set counter = 1
if(empty($counter)){
$counter=1;
$sql1="INSERT INTO $tbl_name(counter) VALUES('$counter')";
$result1=mysql_query($sql1);
}
 
echo "You are visitor number: $counter <br>Your IP Address: ";
echo $_SERVER['REMOTE_ADDR'],"<br>\n";
echo date("m/d/y");
 
// count more value
$addcounter=$counter+1;
$sql2="update $tbl_name set counter='$addcounter'";
$result2=mysql_query($sql2);
 
mysql_close();
?>
 

Re: IP Showing Help

Posted: Mon Mar 17, 2008 9:24 pm
by Christopher
You need to create a second table that contains the IP address and the number associated with it. Note that many users IP addresss change over time.