FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » tracking IP's
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: tracking IP's [message #182068 is a reply to message #182065] Tue, 02 July 2013 08:55 Go to previous message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma:
Senior Member
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.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: PHP Mailto();
Next Topic: Sandbox
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 24 16:03:24 GMT 2024

Total time taken to generate the page: 0.04352 seconds