• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

FlatFile IP Logger

themoose

Sup, Recoil here.
NLC
Here's a flatfile IP logger I wrote and would like to share it with you guys just in case you find it useful :)

Set $variable to whatever you want to log.

PHP:
$logfile = "LOG.txt"; //change this line if you want to change the file it writes to (must exist and CHMOD 0777)
$IP = $_SERVER['REMOTE_ADDR']; //sets the variable for $IP (gets the ip address)
$data = "$variable => $IP  \n"; // sets the text to write to $logfile & adds a new line for the next one (nice and clean)
$fp = fopen("$logfile", "a"); //opens the log file
flock($logfile, LOCK_EX); // start an exclusive lock - prevents the file from being wiped if two people write at same time
fwrite($fp, $data); //writes to the log file
flock($fp, LOCK_UN); // release lock
fclose($fp); //closes the logfile (important!)
    echo "<br /><br />Your IP ($IP) has been Logged with accordance of our T.O.S."; //tells people the've been warned!

I might come back with a mySQL one later.
 
This is assuming your server allows scripts to edit files on the server. If the server does not, it will give you one of many different errors.

One of them being "Warning: Not enough permissions on xxx.php" or something.
 
See line one.

PHP:
$logfile = "LOG.txt"; //change this line if you want to change the file it writes to (must exist and CHMOD 0777)

Should really be 0666, but meh.
 
lol, you dont even have to use a hidden input or post or anything.. you just inject it directly.
 
Back
Top