PDA

View Full Version : An IP Logger I Made


Thomas B.
07-19-2008, 08:30 PM
<?php
$logger = fopen("iplog.txt" , "a");
$ipaddress = $REMOTE_ADDR;
$browser = $HTTP_USER_AGENT;
$timeofday = date("H:i dS F");
fwrite($logger,"---------------------<br />");
fwrite($logger,"IP: $ipaddress <br />");
fwrite($logger,"Browser: $browser <br />");
fwrite($logger,"Time: $timeofday <br />");
fwrite($logger,"---------------------<br />");
fclose($logger);
?>

A very simple code I made. It writes the users IP, browser, and the time they visited the page to a file called iplog.txt. It looks sloppy though. Any way to make it better?

Glanerd
07-19-2008, 08:36 PM
How exactly does it work?

Thomas B.
07-19-2008, 08:58 PM
I said in the first post.

Glanerd
07-19-2008, 09:04 PM
I mean, how would you use it?

Thomas B.
07-20-2008, 12:23 AM
To get a visitors IP address

Glanerd
07-20-2008, 12:26 AM
So I could code it into my website?

Thomas B.
07-20-2008, 12:31 AM
Yes, but name it "log.php" then create a file called "iplog.txt" and make a php require to log.php on your site index. CHMOD to 777.

EDIT: Your site is on Freewebs? lol. and the code won't work on it, Freewebs doesn't support PHP.

Glanerd
07-20-2008, 01:04 AM
Would it work for a forum?

Thomas B.
07-20-2008, 01:06 AM
If the forum isn't hosted by a service (unless they allow FTP access)

Glanerd
07-20-2008, 01:09 AM
Like IPB.

Thomas B.
07-20-2008, 01:11 AM
You can download IPB

Glanerd
07-20-2008, 12:04 PM
Yeah I know.

.:Mouldy Punk:.
07-20-2008, 12:17 PM
Just a random question, why are you storing html (<br/>) in a .txt file? For browsers to be able to parse the log file correctly it'd have to be a .html file. If it's a text file that you plan on saving so that it can be viewed in a text editor, look up carriage returns and line breaks to see how to do them.