Protecting image content from unauthorized users

We all know that this is a very important issue for many web developers. They want to protect direct access or direct readability of their confidential images. A folder containing all the images is open, and everyone can visit this folder, but I want to do something that can protect the contents of my image, which means that if an unauthorized guy is looking for an image, he can get the image by visiting the corresponding folder, but the contents will be invisible or hard to understand. I think that if I get a solution, this question will help many guys. Writing is .htaccessnot always a stable choice. So, after brainstorming, I found several ways how I can protect the contents of the image from direct access. I want to use ImagickwithPHP to perform any kind of image editing.

  • Adding and removing a layer: After loading, add a layer to make the contents of the image invisible. That way, if someone reaches the folder that you saved, the images will be meaningless because they will see the layer, not the contents of the image. Then delete the layer and show them who has the appropriate rights.

  • Convert the image to another format: Convert the image to any format, for example .txt, .exe, .bin, .avi or any other format, so that without editing the image will turn out It will not be visible. Convert back to show it to an authorized user.

  • Image grid: Divide the image into some grids, say if the image is a middle grid of 100 and changes the position of the grid so that the content is fuzzy. To do this, we can name each grid as 1, 2, 3, and so on, and then change the position to $position - 20. So, the grid of position 25 will go up to 5, 100 will go up to 80, 1 will go up to 81 and so on. The reverse is the same as for authorized users.

It is impossible to fully protect, but we can make it harder. I do not know which of the three is possible with Imagickand which is not. Please tell me whether you know. Thanks in advance.

+4
source share
1 answer

public_html ( ). script, , . , .

, html: /var/www your image folder can be: /registered_user/images/

PHP script :

<?php
if(!userLogged() || !isset($_GET['image'])) {
  header('Location: /');
  die();
}
$path = '/registered_user/images/';
$file = clean($_GET['image']); // you can create a clean function that only get valid character for files

$filename = $path . $file;
if(!file_exists($filename)) {
  $filename = '/var/www/images/bogus.jpg';
}
$imageInfo = getimagesize($filename);

header ('Content-length: ' . filesize($filename));
header ('Content-type: ' . $imageInfo['mime']);
readfile ($filename);
+2

All Articles