Ip Logger

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Shiro
Forum Newbie
Posts: 12
Joined: Sat Aug 09, 2003 7:08 am

Ip Logger

Post by Shiro »

Any of you know how I could make an Ip Logger that will log the Ip's Into a php file that will only let me view the ip's? Because im Making it echo into a admin panel page and if they dont have my ip then it will give them an error saying Your not an admin.
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Post by evilmonkey »

well one thing you could do if you have user logins is set a usergroup, and set one to admin. If you're an admin, it will admit you, otherwise tell you something like access denied.

As for the logger itself, all you gotta do is write the line $REMOTE_ADDR to a file with write permissions (777). Not that hard.

Good luck.
Shiro
Forum Newbie
Posts: 12
Joined: Sat Aug 09, 2003 7:08 am

Post by Shiro »

Thanks,

I wasnt thinking, the only thing I was worried about was the public being able to view the Ip's that were logged but i just made 770 which wont let the public view :roll:
Aaron
Forum Commoner
Posts: 82
Joined: Sun May 12, 2002 2:51 pm

Post by Aaron »

Heres some useful logging variables

Code: Select all

$currentPage = @$_REQUEST['currentPage'];

$ip = getenv("REMOTE_ADDR");

$host = @GetHostByAddr($ip); 
    $real_host=chop($host); 
    if($real_host)
	{$host_arr=explode(".", $real_host); 
	$count=count($host_arr); 
	if($count > 1)
	{if(intval($host_arr[$count-1])!=0)
	{$host=substr($real_host,0,strrpos($real_host,".")).".*";} 
    else
	{$host = "*".strstr($real_host, ".");}} 
	else
	{$host=$real_host;}} 
	else
	{$host="";} 

$browser = $HTTP_USER_AGENT;

$referer = getenv("HTTP_REFERER");

$qstring = $QUERY_STRING;
Post Reply