You can use sessions to block people from visiting the link directly, though there are of course many ways for them to get around it, but many people don't know how.
Then use getdata
on a single file to take in the image id or name, and use .htaccess
to rewrite it to .png
, .jpg
, etc. Have a directory structure such as:
images
- view.php
- .htaccess
- files
- - example.gif
- - funny.jpg
- - interesting.png
view.php
checks the session, takes in the getdata
of the image name, it then looks for the file in the files directory and grabs it and then shows the image at the url. So there is one url for them all eg: view.php?img=funny.gif
Then use the image handling functions to get the type image/gif
and use the header('Content-type: image/gif')
and use PHP's image handling functions to show the image.
The role of .htaccess
is to hide the files directory, you could also use mod rewrite to spoof the image urls where they actually direct to one location. The whole purpose of this is so you can set the session on the main website then show the pictures there but the direct url to the image can show an alternate image describing "direct linking is disallowed" or such.