How to see the IPs of user who view a .jpg on your site

This script allows php code to be run every time a certain jpg is loaded. The script below would log the IP that loaded image, the date, referrer, and useragent, but it could be edited to do loads of things. Strictly for educational purpose.

Just create a directory, put this php code into a file which is saved as a .jpg file. You need a real image, in my case called sig.jpg in the same directory, and a file called (in my case) siginfo22.txt - this must be chmod’d to 777. Obviously, file names etc can be different, but must also be changed in code below. Oh, and create a .htaccess, as shown at top of that code.

Here is the script:

create a .htaccess file containing the following two lines:

Options All -Indexes
ForceType application/x-httpd-php

the first one means if someone tries to view directory, they are not
shown it, the second allows the script to work

*/
header(”Content-type: image/jpeg”);
$ip = getenv(”REMOTE_ADDR”);
$date = date(”d”) . ” ” . date(”F”) .
” ” . date(”Y”);
$ref = getenv(’HTTP_REFERER’);
$ua = $_SERVER['HTTP_USER_AGENT'];
$intofile = $ip . ” || ” . $date . ” || ” . $ref
. ” || ” . $ua . “
”;
$hfile = fopen(”siginfo22.txt”, “a”);
fwrite($hfile, $intofile);
fclose($hfile);
$BGImage = imagecreatefromjpeg(”sig.jpg”);
imagejpeg($BGImage);
imagedestroy($BGImage);
?>

Enjoyed reading this article,Now you may want to Subscribe to my RSS feed!or scroll down to leave a comment, or get back to the homepage.

Related Posts by Categories



0 comments:

RSS Entries

Recent Post