php - Deny all access to files via http unless a certain condition is true -
i creating php application , i'm having bit of trouble finding solution problem i'm having. need somehow deny access trying access files on web server (likely returning 403 forbidden error or something) via http unless condition true, such condition checked on per-connection basis. need find best way this, i'm guessing need set special settings in apache can modify php, these apache settings configurable via php. can guess, can write php have little experience advanced apache configurations.
i thinking on maybe if used chmod via php change file's permissions validated user , have them change when connection closed work, if there concurrent connections users connecting afterwords have full access regardless of whether or not valid, bypass validation. maybe there better way however.
thanks help!
put files directory , deactivate http access via .htaccess. write php script checks condition , if true return requested file via php this:
<?php define(dir, "save_folder/"); $filename='the_file_to_show.pdf'; $fileextension= explode(".", $filename); header("content-type: application/$fileextension[1]"); header("content-disposition: attachment; filename=".$filename.""); header("content-length: ".filesize(dir.$filename)); readfile(dir.$filename); ?>
put .htaccess
<directory ~ "save_folder"> order allow,deny deny </directory>
Comments
Post a Comment