I'm making a Admin control panel, and I want to log all the IP's that are going to it.... How would I go about doing this?
| SitePoint Sponsor |
I'm making a Admin control panel, and I want to log all the IP's that are going to it.... How would I go about doing this?
If your using mysql then...
Make sure you have unique ID's for each ip in the table or something like that.PHP Code:$query = "INSERT INTO table (ip) VALUES ('{$_SERVER['REMOTE_ADDR']}')";
mysql_query($query);
Cool i'll do that once i have my database running, is there some way just to write it to a file right now?
try this, "I think"
And that should write each IP on a new line.PHP Code:$fp = fopen("ips.txt", "a");
fputs($fp, $_SERVER['REMOTE_ADDR']."\r\n");
fclose($fp);
Last edited by notepad_coder; Jun 13, 2002 at 14:36.
- the lid is off the maple syrup again!
Ok try this
<?php
gethostbyaddr($REMOTE_ADDR);
$filename = "rupert.log";
$datearray = getdate();
$year = $datearray["year"];
$month = $datearray["mon"];
$day = $datearray["mday"];
$hour = $datearray["hours"];
$minute = $datearray["minutes"];
$fl=fopen($filename,'a');
fwrite ($fl, "[$month/$day/$year, $hour:$minute] $REMOTE_ADDR");
?>
I hope it works
www.bonfire.tk
Rupert your code works great! Thanks!
Thanks
www.bonfire.tk




for that ftp function, couldn't you also use a+? would that make a huge difference? then you could read it, too. right?
Ryan
The REMOTE_ADDR environment variable will not always contain the IP of the person viewing a page, for example if they use a proxy server. So you should check for the presence of X_FORWARDED_FOR - if it is set, then it will give the real IP of the user if they are using a proxy server.
Karl Austin :: Profile :: KDA Web Services Ltd.
Business Web Hosting :: Managed Dedicated Hosting :: From £250/m
Personal Web Hosting :: Budget Web Hosting :: From £50/y
Call 0800 542 9764 today and ask about our Cloud Hosting Platform
X_FORWARDED_FOR is there any other information i could read about. I'm kind of curious about it.
www.bonfire.tk
i don't really know of any official place about it. just check to see if it exists, and if it does, i guess use it instead of REMOTE_ADDR. it can, however, be spoofed into anything since it's sent by the client (unlike REMOTE_ADDR). it is sent by the client in the X-Forwarded-For: header and is available in PHP via $_SERVER['HTTP_X_FORWARDED_FOR'].
there are some other ones like HTTP_CLIENT_IP, but i don't know what's used when.i guess it depends on the proxy.
- Matt
Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
"Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR
Bookmarks