|
Re: tracking IP's [message #182066 is a reply to message #182065] |
Tue, 02 July 2013 02:03 |
Doug Miller
Messages: 171 Registered: August 2011
Karma: 0
|
Senior Member |
|
|
richard <noreply(at)example(dot)com> wrote in news:h54uiific0f9$(dot)k8umottu5xrj(dot)dlg(at)40tude(dot)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.
|
|
|
Re: tracking IP's [message #182067 is a reply to message #182065] |
Tue, 02 July 2013 08:53 |
Arno Welzel
Messages: 317 Registered: October 2011
Karma: 0
|
Senior Member |
|
|
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
|
|
|
Re: tracking IP's [message #182068 is a reply to message #182065] |
Tue, 02 July 2013 08:55 |
The Natural Philosoph
Messages: 993 Registered: September 2010
Karma: 0
|
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.
|
|
|