Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #10018 > unrolled thread

tracking IP's

Started byrichard <noreply@example.com>
First post2013-07-01 20:37 -0400
Last post2013-07-02 09:55 +0100
Articles 4 — 4 participants

Back to article view | Back to comp.lang.php


Contents

  tracking IP's richard <noreply@example.com> - 2013-07-01 20:37 -0400
    Re: tracking IP's Doug Miller <doug_at_milmac_dot_com@example.com> - 2013-07-02 02:03 +0000
    Re: tracking IP's Arno Welzel <usenet@arnowelzel.de> - 2013-07-02 10:53 +0200
    Re: tracking IP's The Natural Philosopher <tnp@invalid.invalid> - 2013-07-02 09:55 +0100

#10018 — tracking IP's

Fromrichard <noreply@example.com>
Date2013-07-01 20:37 -0400
Subjecttracking IP's
Message-ID<h54uiific0f9$.k8umottu5xrj.dlg@40tude.net>
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?

[toc] | [next] | [standalone]


#10019

FromDoug Miller <doug_at_milmac_dot_com@example.com>
Date2013-07-02 02:03 +0000
Message-ID<XnsA1F0E1535BC81dougmilmaccom@78.46.70.116>
In reply to#10018
richard <noreply@example.com> wrote in news:h54uiific0f9$.k8umottu5xrj.dlg@40tude.net:

> 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.

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

> I know this because my hit counter shows there has been new visitors.

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

> 
>     $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?

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. 

[toc] | [prev] | [next] | [standalone]


#10020

FromArno Welzel <usenet@arnowelzel.de>
Date2013-07-02 10:53 +0200
Message-ID<51D294ED.5030706@arnowelzel.de>
In reply to#10018
Am 02.07.2013 02:37, schrieb richard:

> 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.

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.

>     $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?

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
http://arnowelzel.de
http://de-rec-fahrrad.de

[toc] | [prev] | [next] | [standalone]


#10021

FromThe Natural Philosopher <tnp@invalid.invalid>
Date2013-07-02 09:55 +0100
Message-ID<kqu4hu$f6q$1@news.albasani.net>
In reply to#10018
On 02/07/13 01:37, richard wrote:
> 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?


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");
$ipaddr=$_SERVER['REMOTE_ADDR'];
update_db($ipaddr,$time);

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

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..:-)

-- 
Ineptocracy

(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.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web