RecklessArcher Posted April 8, 2013 Share Posted April 8, 2013 (edited) I came across a site that showed how to record the IP address of images requests on a server. It is a fairly simple process with a .htaccess file, the logging process file (iplogger.php) the log file (logger.html) and obviously the image. Now I'm pretty new to PHP so I'm not sure if this process is sound, but I haven't gotten it to work on three different servers so if someone could look over the process I'd be delighted. .htaccess file **the "image.jpg" must be renamed to your image file name** RewriteEngine on RewriteRule ^image.jpg$ iplogger.php iplogger.php file <?php $log = 'logger.html'; $ip = $_SERVER['REMOTE_ADDR']; $page = $_SERVER['REQUEST_URI']; $refer = $_SERVER['HTTP_REFERER']; $date_time = date("l j F Y g:ia", time() - date("Z")) ; $agent = $_SERVER['HTTP_USER_AGENT']; $fp = fopen("logger.html", "a"); fputs($fp, " <b>$date_time</b> <br> <b>IP: </b>$ip<br><b>Page: </b>$page<br><b>Refer: </b>$refer<br><b>Useragent: </b>$agent <br><br> "); flock($fp, 3); fclose($fp); ?> The logger.html file was blank and is supposed to be amended by the server as the image files are accessed. Now all these files are to be uploaded to the same directory along with the image file. Now supposedly when the image file is accessed, the IP address of the requesting party is supposed to be logged in the logger.html file. I can't see a way for the image file to trigger the logger.php file. -Is there a way to make the image link work where when the image is viewed it will be recorded in the HTML file? Edited April 8, 2013 by RecklessArcher Quote Link to comment Share on other sites More sharing options...
requinix Posted April 8, 2013 Share Posted April 8, 2013 I can't see a way for the image file to trigger the logger.php file. -Is there a way to make the image link work where when the image is viewed it will be recorded in the HTML file? That's what the .htaccess does. Quote Link to comment Share on other sites More sharing options...
RecklessArcher Posted April 8, 2013 Author Share Posted April 8, 2013 That's what the .htaccess does. Then why doesn't it log when the image file is displayed? Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 8, 2013 Share Posted April 8, 2013 What version of PHP are you using? When you lock the file, you didn't unlock it. Why are you locking it in the first place, and after you write it? Quote Link to comment Share on other sites More sharing options...
RecklessArcher Posted April 8, 2013 Author Share Posted April 8, 2013 What version of PHP are you using? When you lock the file, you didn't unlock it. Why are you locking it in the first place, and after you write it? PHP Version 5.3.10-1ubuntu3.6I didn't know I was locking it. How is that happening and how do I not do it? As I said, I'm just learning PHP. Thanks for pointing that out! Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 8, 2013 Share Posted April 8, 2013 (edited) flock($fp, 3); If you don't know what your code does, you're not really learning, are ya Look up every function you use and make sure you understand it. Type in php.net/function here and read. flock Changelog: 5.3.2 The automatic unlocking when the file's resource handle is closed was removed. Unlocking now always has to be done manually. Edited April 8, 2013 by Jessica Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.