fish man
fish man

Reputation: 2710

php track who use my image

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

Answers (3)

Can Tecim
Can Tecim

Reputation: 587

I would do any job top of the php file and then use readfile function

Upvotes: 1

Giberno
Giberno

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

hellcode
hellcode

Reputation: 2698

imagejpeg is the wrong function. Try this instead:

echo file_get_contents($_GET['id'].'.jpg');

Upvotes: 1

Related Questions