php - Protect 1000+ html files in directory without editing all of them -


i trying make website have log in in order view files. got login , running mysql databases , working fine, except don't want manually put edit 1000+ html files check if user logged in. have tried using htaccess, popup ugly can't stand it.

now, question is, can password-protect bunch of files on website without manually modifying of them, or can make "htaccess login form" good. thanks.

you put of html files in directory outside of webroot, refer them through url rewriting or basic querystring variable passed single php script.

for example:

<?php // file ?whichfile=(...) $whichfile = $_get['whichfile'];  // put logic here verify user logged in / has valid session id, etc. // should put checks on value passed through "whichfile" // prevent users accessing things shouldn't.  simple regular expression // check verify "whichfile" follows fixed format do:  12345.html, etc  if (file_exists("/var/www/folder/out/of/webroot/".$whichfile)) {    $blob = file_get_contents("/var/www/folder/out/of/webroot/".$whichfile);    header("content-type: text/html; charset=utf-8");    print $blob; } 

Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -