Jump to content
xisto Community
electriic ink

How To: Hide The Real Url Of Your Images using php

Recommended Posts

Hiding The Real URL To Your Images

Using php to protect the real url to your images

 

In this tutorial I will explain how you can easily hide the real .gif or .jpg url to your images by masking it with php. This is not hard to do.

 

A basic amount of php knowledge is required for this tutorial.

 

Note: This will not protect your images for content robbers.

 

 

1. Create a new php file and save it as img.php in the public_html directory

 

2. Add the following code to img.php. All important notes and information are explained in the remming.

 

<?$ext = $_REQUEST["type"]; $filename = $_REQUEST["fl"];/* $img is the directory where all your images are stored */$img = "images/"; /* Firstly let's see if the variables have information in them */if (!$ext) { echo "Could not find appropiate information";exit;} if (!$filename) {  echo "Could not find appropiate information";exit;}if (!$img) {   echo "Could not find appropiate information";exit;}/* Extensions should be shown as numbers in the url for good protection. We will now redefine $ext matching the appropiate number from requested variable "type" */if ($ext == 1) { $ext = "jpg";} else if ($ext == 2) { $ext = "gif";} else if ($ext == 3) { $ext = "png";}/* The filename is not shown as numbers so we now have the "ingredients" needed to show the image. Now lets see if the image exists */if (!file_exists($img . $filename . "." . $ext)) {  echo "Could not find image";exit;}/* Now lets show the image. This is just a simple include statement */include $img . $filename . "." . $ext;?>

3. Change the image urls on your webpages to look like the following

 

<img src="/img.php?fl=filename&type=1" alt="Image">

If you want to download the code, attached is a text file displaying all of this.

 

And that's really all there is to it. Enjoy your php images :P

 


Share this post


Link to post
Share on other sites

Whenever I am about to post an image on my site alot of times I don't want my images hotlinked because of bandwidth.

Well, you could disable hot linking for images.

Share this post


Link to post
Share on other sites

Wow that is a very useful script. Whenever I am about to post an image on my site alot of times I don't want my images hotlinked because of bandwidth.

161025[/snapback]


This would still allow your image to be hotlinked... it'd just disguise the URL. Most forums don't allow dynamic urls, so it couldn't be posted... but would work fine in coded html.

Share this post


Link to post
Share on other sites

Kudos cmatmeXtra, you could really make a script like that big...  You could release it on Source Forge, it would be quite popular, excelant work... :D

161256[/snapback]


Thanks. I sent the script up to hotscripts several hours back now. Just awaiting their confirmation :P

Share this post


Link to post
Share on other sites

Indeed, great PHP script.It's a useful way to put away lots of people who could hotlink the images. Oh, and good luck with it on hotscripts. :P

Share this post


Link to post
Share on other sites

Neat trick, it really is. But as cmatcmextra pointed out, this is not to prevent content robbing. And if you are worried about hotlinking, your Xisto hosting cPanel has nice options for hotlinking prevention.But it's still a good example of how you can mask a file, or just put something between the "getter" and the file. I was wondering about one thing, will this affect the caching of images on your webpages? I can imagine that a browser might say "wow, a dynamically generated page, I won't cache it". Which means quite an increce in bandwidth usage if you have a graphics-heavy site.

Share this post


Link to post
Share on other sites

not bad but another way to prevent people from hijacking your images do what ign.com doest, water mark it, but this could be a useful script hopefully its gets downloaded alot.

Share this post


Link to post
Share on other sites

Really useful. I?ve downloaded the script and I hope I can make it work. People who hotlink is very annoying (although I have to admit that I have done it several times in the past, :D ).Thanks!

Share this post


Link to post
Share on other sites

Really useful, thanks for the script.

 

not bad but another way to prevent people from hijacking your images do what ign.com doest, water mark it, but this could be a useful script hopefully its gets downloaded alot.

163986[/snapback]


Does anyone a way insert watermarks automatically in the images. I mean a PHP script or a free program that run in a server.

Share this post


Link to post
Share on other sites

Does anyone a way insert watermarks automatically in the images. I mean a PHP script or a free program that run in a server.

166609[/snapback]


Please start a new topic in the programming languages forum....

Share this post


Link to post
Share on other sites

Thank you for this very useful script. This, along with a watermark on all the images, and the available protection through Trap 17 would really help deter a thief.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.