Created
December 5, 2012 15:03
-
-
Save stalmok/4216203 to your computer and use it in GitHub Desktop.
Revisions
-
stalmok created this gist
Dec 5, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ /** * Original post: http://www.thebigblob.com/how-to-restrict-user-access-to-content-in-folders-using-php-and-apache-htaccess-files/ */ # The .htaccess file RewriteEngine on RewriteBase / RewriteCond %{REQUEST_URI} ^\/(path\/to\/some\/folder|dummy)\/.*$ RewriteRule !^((.*.php)|(.*\/))$ authorize.php # The PHP file (authorize.php) <?php // Perform authentication and authorization here if($hasAccessToFolder) { // Get the file if(file_exists($_SERVER['DOCUMENT_ROOT'].$_SERVER['REQUEST_URI'])) { // Open the file for reading $fp = fopen($_SERVER['DOCUMENT_ROOT'].$_SERVER['REQUEST_URI'], 'r'); // Set mime type to header header('Content-type: '.mime_content_type($_SERVER['DOCUMENT_ROOT'].$_SERVER['REQUEST_URI'])); // Send the contents of the file the browser fpassthru($fp); fclose($fp); } else { // File not found die('File not found'); } } else { die('Access denined'); }