sford999
04-26-2004, 05:27 PM
I`ve a directory on my server where I want to log IP`s that try to access the directory, can be either flat file or SQL tables.
Anyone know of one?
Thanks
Anyone know of one?
Thanks
![]() | View Full Version : Directory logging (pref php) sford999 04-26-2004, 05:27 PM I`ve a directory on my server where I want to log IP`s that try to access the directory, can be either flat file or SQL tables. Anyone know of one? Thanks ambirex 04-26-2004, 05:37 PM I don't know of one, but there are two ways that come to mind. 1. grep your access logs for that directory and parse the info. (downside: not real-time) 2. have a mod_rewrite rule that shuttles everything to a script, that opens the file and sends it to the user (downside: large files might make it choke) null 04-26-2004, 09:21 PM PHP can't log access to the directory. Script works only when you call it. There are several ways you can do it 1) Create index.php. In most cases that will cover 90% of the requests. 2) Using Apache mod_rewrite you can redirect all request to the script RewriteEngine On RewriteRule /directory/(.+) /directory/script.php [L] Create a script that will get the IP address and write it into the file <?php $addr = $_SERVER["REMOTE_ADDR"]; if(!$addr) die("No IP, no access"); // Make sure to give write permissions to the log file // Better to keep the file away from Apache access $fp = fopen("ip.log", "a"); if(!$fp) die("Could not open file"); // Write IP and time accessed fwrite($fp, $ip." - ".date("l dS of F Y h:i:s A")); fclose($fp); ?> You are done! Question? PM me. sford999 04-26-2004, 09:32 PM Thanks that worked perfectly null 04-26-2004, 09:34 PM Glad I helped. null |