hey guys,

i'm trying to make a script where the ip address of visitors to a site are logged in a .txt file, then trying to figure out a way to count the lines to determine the number of hits... i also want to block one particular ip address from being logged at all when visiting the site.

i know i have to use REMOTE_ADDR to find the user's ip address, but i'm not sure about how to add up the lines to a number after the addys have been written to the file.

any help is greatly appreciated... i may be a newb but i am quickly falling in love with this language!

    With one IP address per line, you can use [man]file/man to read them into an array. Of course, you could also store them in a database, which might be easier.

    That said, I find IP address blocking disgusting. I have been blocked because I share the same IP address from time to time with many other people from the same country.

      As laserlight suggested it may be better to use a database.

      here is a basic one which updates if they have visited before.

      my table includes 5 columns

      (ip_tracking)
      ip_address | date_last | visits | username | user_id

      <? session_start();
      
      $hostname = $_SERVER['REMOTE_ADDR'];
      
         include("dbinfo.inc.php");
      
      $query="SELECT DATE_FORMAT(date_last, '%a %b %e %Y %T') AS date_last FROM ip_tracking WHERE  username ='$user' ";
      $result = mysql_query($query) or die('MySQL error - ' . mysql_error() . "<hr>Query: $query"); 
      $num=mysql_num_rows($result);
      while ($row = mysql_fetch_array($result)) {
      
      $last_visited = $row["date_last"];
      
      } 
      if($last_visited);
      {
      
      include("dbconn.inc.php");
      
      $sql = ("UPDATE ip_tracking SET date_last = NOW() WHERE username ='$user'"); 
      $sql1 = ("UPDATE ip_tracking SET ip_address ='$hostname' WHERE username = '$user'"); 
      $sql2 = ("UPDATE ip_tracking SET user_id='$user_id' WHERE username = '$user'");
      $result = mysql_query($sql); 
      $result1 = mysql_query($sql1); 
      $result2 = mysql_query($sql2);
      $sql3 = mysql_query("SELECT * FROM ip_tracking WHERE  username ='$user'") or die(mysql_error());
      while($visits = mysql_fetch_array($sql3))
      {
      $visits = $visits['visits'];
      $visits_new = $visits + 1;
      }
      
      $query = "UPDATE ip_tracking SET visits = '$visits_new' WHERE username ='$user'";
      mysql_query($query, $conn) or die(mysql_error());
      }
      
      
      if (empty($last_visited)){
      $firsttime='First Visit';
      $visits_new='First Visit';
      
       include("dbconn.inc.php");
      
        $query = "INSERT INTO ip_tracking VALUES ('$hostname',NOW(),'','$user','$user_id')";
                mysql_query($query);
      }
       ?>

      Then to display

      $query = "SELECT * from ip_tracking ORDER by date_last DESC" or die (mysql_error());

      to find who was the last visited, visits etc(use while loop), as the update covers changes it works ok as IP address change but username's stay the same

        Write a Reply...