PDA

View Full Version : IP Tracker



Nikkolus
10-03-2004, 07:22 AM
I found this script:


<?

/*
* This script is copyright PHPGarage.com (On Line Construction Inc.). It may be used,
* changed, and distributed freely as long as this message and/or some type of recognition
* is given to PHPGarage.com or On Line Construction Inc.
*
* http://www.phpgarage.com
* http://www.onlineconstructioninc.com
*
*/
$register_globals = (bool) ini_get('register_gobals');
if ($register_globals) $ip = getenv(REMOTE_ADDR);
$ip = $_SERVER['REMOTE_ADDR'];

$CurrentDate = date("m-d-Y h:ia");
$TextFile = "aimtracker.html";
$Body = "$_REQUEST[name] $ip<br>";
$Body .= file_get_contents($TextFile);
$Anon = "Unknown User";
{
if ( empty ($_REQUEST[name]) ) {
($FP = fopen ($TextFile, "w") )
fwrite($FP, $Anon);
fclose($FP);
}
{
else (($FP = fopen($TextFile, "w"))
fwrite($FP, $Body);
fclose($FP);
}
?>

But it gives me this error when I try to execute it:

Parse error: parse error, unexpected T_STRING in /home/public_html/folder/main2.php on line 24

Line 24 is fwrite($FP, $Anon);

Any ideas? I'm pretty new to php, sorry.

Odin
10-03-2004, 09:18 PM
Sorry, I changed the script quite a bit, hopefully you can still see what it's doing. Also I added the date into the log seen as it wasn't doing anything, and changed the writing for an unknown user, which would've wiped out your log.



<?php

/*
* This script is copyright PHPGarage.com (On Line Construction Inc.). It may be used,
* changed, and distributed freely as long as this message and/or some type of recognition
* is given to PHPGarage.com or On Line Construction Inc.
*
* http://www.phpgarage.com
* http://www.onlineconstructioninc.com
*
*/

$TextFile = "aimtracker.html";
$contents = file_get_contents($TextFile);
$CurrentDate = date("m-d-Y h:ia");
$ip = (isset($_SERVER)) ? $_SERVER['REMOTE_ADDR'] : $HTTP_SERVER_VARS['REMOTE_ADDR'];
$info = (empty($_REQUEST['name'])) ? 'Unknown User' : $_REQUEST['name'].' '.$ip;
$log = $CurrentDate.' '.$info."<br />\n".$contents;
if($FP = fopen($TextFile, "w")){
fwrite($FP, $log);
fclose($FP);
}

?>

Nikkolus
10-04-2004, 12:30 AM
Thanks a bunch Odin! Works great.

Nikkolus
10-04-2004, 06:50 PM
Doh, ok almost there!

It doesn't log the IP for anonymous users, I can't tell why not, any ideas?

Odin
10-04-2004, 07:17 PM
Ok, change:
$info = (empty($_REQUEST['name'])) ? 'Unknown User' : $_REQUEST['name'].' '.$ip;
$log = $CurrentDate.' '.$info."<br />\n".$contents;

To:
$user = (empty($_REQUEST['name'])) ? 'Unknown User' : $_REQUEST['name'];
$log = $CurrentDate.' '.$user.' '.$ip."<br />\n".$contents;