Visitor Logger

Page 1 of 1

0 Replies - 347 Views - Last Post: 13 June 2006 - 02:14 PM

#1 max302  Icon User is offline

  • Proud supporter of the lulz
  • member icon

Reputation: 3
  • View blog
  • Posts: 1,281
  • Joined: 05-March 06

Visitor Logger

Posted 13 June 2006 - 02:14 PM

Description: Add your Database parameters, configure your database, install to any web page and you are ready to go! to avoid confusion, you might want to make a function out of this script and run it from an include.Logs visits with ip with a limit one per day. I use this script on my blog to record visits.
<?PHP
/*=============================================
  |Visitor IP Log by Maxime Rousseau          |
  |===========================================|
  |This records all visitors using IP and the |
  |number of times that this computer has     |
  |requested the page, with a limit of 1 per  |
  |day. I have added y to every variable to   |
  |eliminate the need for disambiguation.     |
  =============================================*/
 
/*-------DB Params-------*/
$ydbuser = "";          // Database user used, change as needed
$ydbhost = "";          // Database used
$ydbpasswd = "";               // Database user password
$ydbdatabase = "";          // Database
$ydbconnection = mysql_connect($ydbhost,$ydbuser,$ydbpasswd);
$ydb = mysql_select_db($ydbdatabase,$ydbconnection);
/*-----End DB Params-----*/

$ytoday = date("Ymj");
if (strlen($ytoday) == 5)
{
$ytoday[6] = $ytoday[5];
$ytoday[5] = 0;
}
$yuserip = getenv("REMOTE_ADDR"); 
$ycheckip = "SELECT visitcount FROM visitcount WHERE userip = '$yuserip'";
$ycheckipq = mysql_query($ycheckip);
$ycheckipr = mysql_fetch_array($ycheckipq);
$yprevvisits = "SELECT lastvisit FROM visitcount WHERE userip = '$yuserip'";
$yprevvisitsq = mysql_query($yprevvisits);
$yprevvisitsr = mysql_fetch_array($yprevvisitsq);
if ($ycheckipr == 0)
     {
     $yadduser = "INSERT INTO visitcount (userip,lastvisit,visitcount) VALUES ('$yuserip','$ytoday',1)";
     mysql_query($yadduser);
     }
else if ($yprevvisitsr != $ytoday)
     {
     $yvisits = $ycheckipr[$visitcount];
     $yvisits++ ; 
     $yupdatevisits = "UPDATE visitcount SET visitcount = '$yvisits' AND lastvisit = '$ytoday' WHERE userip = '$yuserip'";
     mysql_query($yupdatevisits);
     }
?>



Is This A Good Question/Topic? 0
  • +

Page 1 of 1