tracking IP's

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I want a simple script that will keep track of IP's in a mysql table.

This script works. But puts the IP in a text file.
It's ok, but doesn't seem to detect any other IP but mine.
I know this because my hit counter shows there has been new visitors.

    $ipaddress = $_SERVER['REMOTE_ADDR'];
    $date = date ("M dS H:i:s");

    $message = "$page _ $ipaddress _ $date\n";

    $File = "track.txt";
    $Open = fopen($File, "a+");
    if ($Open){

    fwrite($Open, "$message");
    fclose ($Open);

I have been looking around for a script but can't seem to find one that
works the way I want.
anyone have such a script online somewhere?

Re: tracking IP's

Quoted text here. Click to load it

No big surprise there -- no reason to think that there are any hits from any other IP address  
but yours.

Quoted text here. Click to load it

Your hit counter is being incremented, anyway -- doesn't mean there are any new visitors.  
(Hit counter could be faulty, for example.)

Quoted text here. Click to load it

Write your own, it's not that hard. You already have various scripts that insert data into  
MySQL tables; here, you have a script that writes IP addresses into a text file. Pretty trivial  
matter to modify this to write to a MySQL table instead.  

Re: tracking IP's

Am 02.07.2013 02:37, schrieb richard:

Quoted text here. Click to load it

How do you check the counter? If you refresh the page with the counter
in your browser this is of course also a hit - but just by you.

Quoted text here. Click to load it

A script is not enough - you also need a database and a table for this.

Try to learn PHP and at least the basics of SQL and do not just
copy&paste - otherwise you will have scripts with security holes just
because you don't understand what the scripts really do and you don't
see the security problems in the code.

Arno Welzel

Re: tracking IP's

On 02/07/13 01:37, richard wrote:
Quoted text here. Click to load it

What I have here is that a common set of libraries included in all main  
pages  do the following

$time=date("Y-m-d H:i:s");

function update_db($ipaddr,$time)
      $result=mysql_query("select id, hits from ipdata where  
           if($result && mysql_num_rows($result) >0) //update existing
          $hits=mysql_result($result, 0, 'hits');
          mysql_query(sprintf("update ipdata set  
hits='%d',last_access='%s' where id='%d'",$hits+1,$time,$id));
     else // insert record into table
         mysql_query(sprintf("insert into ipdata set  
ipaddr='%s',last_access='%s',hits='1', whois='%s'",

Its old code and I wouldn't write it again this way, but it more or less  
works. Two rapid hits from the same IP address result in two inserts  
sadly - should have done an update or insert sql statement.
Also should use Mysqli lib instead of mysql.

The whois lookup is massively vile code and I wouldnt do that again.  
Better to have a table of all the ip domains there are in the world and  
link to that..:-)


(in-ep-toc?-ra-cy) ? a system of government where the least capable to lead are elected by the least capable of producing, and where the members of society least likely to sustain themselves or succeed, are rewarded with goods and services paid for by the confiscated wealth of a diminishing number of producers.

Site Timeline