Jump to content

how to protect hot-linking in image.php?


mark103

Recommended Posts

Hi guys,

 

I need your help with my php script. On my script, I'm currently working with image where I can hot-link them from another website while it is on protected. when you click right-mouse button on firefox, you could see something like "view page source" which is disabled. when you click on "save page as", you can save the image as "image.php". when you open them, you would not be able to read due to the image but you can find the real image link in image.php where i want to protect them. :(

 

here's the currently code:

 

<?php
session_start();
    define('DB_HOST', 'localhost');
    define('DB_USER', 'myusername');
    define('DB_PASSWORD', 'mypassword');
    define('DB_DATABASE', 'mydbname');

$id = (int)$_GET['id'];

$errmsg_arr = array();
$errflag = false;

$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
    die('Failed to connect to server: ' . mysql_error());
}

$db = mysql_select_db(DB_DATABASE);
if(!$db) {
    die("Unable to select database");
}   

function clean($var)
{
    return mysql_real_escape_string(strip_tags($var));
}
  $qrytable1="SELECT images FROM image_list WHERE id=$id";
  $result1=mysql_query($qrytable1) or die('Error:<br />' . $qry . '<br />' . mysql_error());

while ($row = mysql_fetch_array($result1)) {
   $image = $row['images'];
   $details = getimagesize($image); 
   header ('Content-Type: ' . image_type_to_mime_type($details[2]));
   echo readfile($image), "<p id='images'>",  $row['images'] . "</p>";
} 
?>

 

 

I guess that there must be a way to protected the url in the php script where i can hide them. It should be easy to modify but I am not sure what line I need to adjust to make it protected.

 

Can you please help me in what line I need to modify in order to protected the hot-linking in my php?

Link to comment
Share on other sites

I'm not entirely sure what you are trying to achieve but it sounds like you are trying to hide the fact your images are coming from a php script?

 

If so you could use mod_rewrite to act as a alias to the file e.g. image012.jpg being an alias for myimage.php

 

RewriteEngine on
RewriteRule ^([A-Za-z0-9]+)\.jpg$ myimage.php?image=$1

 

If that's what you meant?

 

If it was about stopping people altogether getting an image from you website then it is impossible as if you serve an image then you have made it publicly accessible. You can do certain things like protecting how people access the image such as with keys or host dependencies.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.