TeamPhotoshop
Reviews, updates and in depth guides to your favourite mobile games - AppGamer.com
Forum Home Latest Posts Search Help Subscribe

ip log..

Page: 1 Reply
Dec 29th 2003#135312 Report
Member since: Jul 7th 2003
Posts: 24
is there any way to logg a user ip? (prefer php)
(if you wonder why i want to log ip's its to avoid abuse, it scares the 12 year olds away ;) im planning to show it to them And log it)
Reply with Quote Reply
Dec 29th 2003#135316 Report
Member since: Nov 6th 2001
Posts: 240
[PHP]
$ip = $_SERVER['REMOTE_ADDR'];
?>
[/PHP]

Where do you want to store the ip address, text file or MySQL database?
Reply with Quote Reply
Dec 29th 2003#135317 Report
Member since: May 22nd 2003
Posts: 315
[PHP]

$ip = $_SERVER["REMOTE_ADDR"];


?>
[/PHP]

This'll get the IP of the client... you should check php.net... I recall them having tons of info on what you can get from the client to put in the log [referrers... etc].

You could use the fopen and fwrite functions to write the data to a flat file...

Edit: Crap, I was 2 seconds too slow =[
Reply with Quote Reply
Dec 29th 2003#135319 Report
Member since: Jul 7th 2003
Posts: 24
Originally posted by qtone
Where do you want to store the ip address, text file or MySQL database?


text file =)
Reply with Quote Reply
Dec 29th 2003#135325 Report
Member since: May 22nd 2003
Posts: 315
Example taken from php.net:

[PHP]

$filename = 'test.txt';
$somecontent = "Add this to the file\n";

// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {

// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}

// Write $somecontent to our opened file.
if (!fwrite($handle, $somecontent)) {
echo "Cannot write to file ($filename)";
exit;
}

echo "Success, wrote ($somecontent) to file ($filename)";

fclose($handle);

} else {
echo "The file $filename is not writable";
}
?>

[/PHP]
Reply with Quote Reply
Dec 29th 2003#135326 Report
Member since: Nov 6th 2001
Posts: 240
Very, very basic ip logging
[PHP]
// include this file in each page
// you want to log
// -> include("log_ip.php");

// logfile
$logfile = "logd/log_file.log";

// get the IP address
$ip = $_SERVER['REMOTE_ADDR'];
// set date
$date = date("Y/m/d H:i:s",time());

// open file for writing
// make sure you have write access
// to the log file/folder
$fh = @fopen($logfile,"a") or die("Could not open log file");
@fwrite($fh,$ip."|".$date."\r\n") or die("Could not write to log file");
@fclose($fh);

/*
log file will look like this:
127.0.0.1|2003/12/29 20:49:17
127.0.0.1|2003/12/29 20:49:18
*/
?>
[/PHP]
Reply with Quote Reply
Dec 31st 2003#135524 Report
Member since: Jul 7th 2003
Posts: 24
thanks alot guys =)
Reply with Quote Reply
Page: 1 Back to top
Please login or register above to post in this forum