Forum Moderators: coopster

Message Too Old, No Replies

Help about doing a file php hide for image URL

image.php?img=001

         

romzinho2k7

6:19 pm on Apr 4, 2006 (gmt 0)

10+ Year Member



Friends, need their of the help again =)

Following, I tried to do a script that hide for image URL ( image.php?img=001 ) where 001 is the iD corresponding to image on the data base.

I did that script:
<?php
include("config.php");

$img = $_GET["img"];

$query = mysql_query("SELECT * FROM files WHERE id='$img'") or die(mysql_error());
$x = mysql_fetch_array($query);
$id = $x["id"];
$photo = $x["photo"];

$file = fopen ("$photo", "rb", 1);
$data = fread($file, filesize("$photo"));
fclose ($file);
Print($data);
?>

So, I catch this image with <img src="image.php?img=001">

But if the guy click with the right button of the mouse on top of the image and to click in properties will see the link [localhost...] ( I am exhibiting the files of my computer ) if the guy put for URL in the navigator, it is going to appear a lot of Crunched codes.

I wanted if it put [localhost...] was exhibited the image, and not these codes.

Will it it be what anybody could help?

Thanks again.

whoisgregg

6:43 pm on Apr 4, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



header("Content-type: image/png");

or
header("Content-type: image/jpeg");

or
header("Content-type: image/gif");

Before you send any output to the browser.

romzinho2k7

7:08 pm on Apr 4, 2006 (gmt 0)

10+ Year Member



Thank you very much

whoisgregg

10:08 pm on Apr 4, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Also, you should be able to replace all of:

$file = fopen ("$photo", "rb", 1); 
$data = fread($file, filesize("$photo"));
fclose ($file);
Print($data);

With:

readfile("$photo");

I'm curious why you are implementing this script... Are you doing this to try and prevent hotlinking?

romzinho2k7

3:19 am on Apr 5, 2006 (gmt 0)

10+ Year Member



Yes, I want to avoid that they use server band with hotlinking.

whoisgregg

8:56 pm on Apr 5, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So, you will be adding additional checks into this php script to prevent the hotlinking? As it stands the url could still be used from another site.

You may also want to look at this library thread [webmasterworld.com] that discusses in-depth methods that use Apache mod_rewrite.