script php that return an image file

313 views Asked by At

it's possibile to create a script in php that is used in img tag to show an image, for example:

<img src="http://domain.com/img.php?id=1" />

and when is called the script count the impressions (no problem here) and at the end return the image in gif/jpg format.

for now i use:

header( "Content-type: " . $type );
readfile( $img );

it work perfectly, but it don't return the image file in gif/jpg format..

i need to change this script in way that when i type domain.com/img.php?id=1 in the browser, the browser address should change to domain.com/image.gif

is this possibile?

1

There are 1 answers

2
ReynHartono On

It's possible
Just use htaccess rewrite code to hide the php address.
You may try this code on your .htaccess file

<IfModule mod_rewrite.c>

RewriteEngine on

RewriteRule ^*(.*)\.gif$ img.php?id=$1 [L]

Options All -Indexes

</IfModule>

It will change img.php?id=XXX into XXX.gif (not a real image file, just for masking the real address)