Ip tracer

By F*U*R*B*Y* on Feb 20, 2006

i asked for one, in the request, so then i thought i would learn on how to write information to a file, so now i have made a simple script that will record visitors IP, the time, and the date and there browser

<?php
//Set the date so we can store it in the text file. 
$tdate = date("dS F Y h:i:s A");

//Check if there is a referer
if (!$HTTP_REFERER) { $HTTP_REFERER = "(NONE)"; }

//Store it in the counter.txt file ! DONT FORGET TO SET COUNTER.TXT CHMOD 777 !
$fp = fopen("counter.txt", "a");
$line = "IP Address: $REMOTE_ADDR - Date: $tdate - Referer: $HTTP_REFERER - Browser: $HTTP_USER_AGENT\n";
fwrite($fp, $line);
fclose($fp);

echo "Your IP is $REMOTE_ADDR<br>";
echo "the time is $tdate<br>";
echo "you are using $HTTP_REFERER";
?>

Comments

Sign in to comment.
smithveg   -  Jan 04, 2009

What if i need to track the country, and state by using an IP?

 Respond  
DiGiTaL   -  Sep 16, 2008

Lol I'm not bitching. I apologize it seems that way.

 Respond  
Jonesy44   -  Sep 16, 2008

They do tend to go into complexity's though. This is a simple good example. Not sure why you're bitching about it :/

 Respond  
DiGiTaL   -  Sep 16, 2008

There is a better way to understand these small scripts and how they work...

http://php.net/fopen

 Respond  
Jonesy44   -  Sep 16, 2008

To be honest; i think all of these small scripts are a great help, as examples of stuff like what fopen can do, and let's be honest, anyone who does not know fopen, would not really be running/coding a high traffic website :/

 Respond  
DiGiTaL   -  Sep 16, 2008

You SHOULD never consider the superglobal variable's elements an actual variable. Very bad practise.
Thats like treating $_POST['id'] to $id...

Use the following: $_SERVER['REMOTE_ADDR'] and if you want concatenate it inside a string use this: {$_SERVER['REMOTE_ADDR']}

 Respond  
sean   -  Sep 16, 2008

you should check out file_put_contents();

 Respond  
Hawkee   -  Sep 15, 2008

Never too late to fix it up ;)

 Respond  
F*U*R*B*Y*   -  Sep 15, 2008

Date Added Feb 20, 2006

.......

two years old dude, let it go ;)

 Respond  
unknowN-   -  Sep 14, 2008

Hawkee is right, and second to that, if the site has high amounts of traffic the fopen will get errors because it will be locked by the same script running for another user. Use MySQL instead. Also why are you using the $HTTP_* variables? They are deprecated and have been replaced with the $_SERVER array.

 Respond  
F*U*R*B*Y*   -  Oct 13, 2007

counter.txt

 Respond  
Joshuaxiong1   -  Oct 11, 2007

Where can I view the ip that are being stored?

 Respond  
F*U*R*B*Y*   -  Feb 21, 2006

what about the people not using apache...

 Respond  
Hawkee   -  Feb 20, 2006

This information is already automatically stored in your Apache access_log. I don\'t see why you need to create a copy. A high traffic site would kill server space twice as fast with the addition of this.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.