Reputation: 2710
I want track who used my image in php script. file list.
/var/www/html/1.jpg
/var/www/html/tracker.php
/var/www/html/.htacess
.htacess code
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(.*).jpg$ tracker.php?id=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
tracker.php
<?php
header('Content-type:image/jpeg');
imagejpeg($_GET['id'].'.jpg');//echo '<img src="'.$_GET['id'].'.jpg'">';
file_put_contents('log.txt',$_GET['id'].' '.$_SERVER['REMOTE_ADDR'].' '.var_dump(apache_request_headers()));
?>
the log.txt has been created, but the image doesn't display in browser. where is the problem?
Upvotes: 0
Views: 224
Reputation: 587
I would do any job top of the php file and then use readfile function
Upvotes: 1
Reputation: 1333
<?php
$image=imagecreatefromjpeg($_GET['id'].'.jpg');
header('Content-Type: image/jpeg');
imagejpeg($image);
file_put_contents('log.txt',$_GET['id'].' '.$_SERVER['REMOTE_ADDR'].' '.var_dump(apache_request_headers()));
?>
Upvotes: 0