php - Proper method of storing private images on server? -
i have written php script retrieve images not under public_html folder. script authenticates user has permission view image displays it. image permissions set "0755"
secure method prevent other people viewing private images? hashing image file name add security benefit? there other alternative methods improve script?
script of image_retrieval.php
<?php include '../user_verification.php'; $image_request = $_get['image_request']; $pic = file_get_contents("/home/username/images/'.$image_request.'"); header('content-type: image/jpeg'); echo $pic; ?>
script of display_image.php
<?php include '../world/verification.php'; $image_request = $_get['image_request']; echo"<img src='http://www.domainname.com/request_image.php?userid=$userid&image_request=$image_request'>"; ?> <form id='image_requester' method='get' action='display_image.php'> <input type="text" id="image_request" name="image_request"> <input type="hidden" value="<?echo"$userid";?>" id="userid" name="userid"> <input type="submit" value="request"> </form>
since images not publicly available enough. thing hashed names more unique , store them under 1 dir, if wanted recommend using timestamps not clash other images ever!
otherwise storing of images hashes prove useful if auth layer somehow compromised. if happens isn't long before can list in there.
from code have posted above seems images in 1 place, store each users images separately if auth layer somehow compromised person, persons images @ risk rather everyone's. if needed hash them said or store them such names don't clash each other, while storing reference image in database.
Comments
Post a Comment