AndrewJ1313 Posted April 21, 2010 Share Posted April 21, 2010 I have a section of a web site password protected via htaccess. The issue I am having is, I want to be able to have the user log in using an HTML form validating the user from a database of about 400 users instead of the default pop up for htaccess. I do not have access to directly alter code within the htaccess file as it is only controlled through a cPanel interface. Is there a work around to this beside passing "username:[email protected]" ? From what I have read on google, this function doesn't even work in IE anymore and in Firefox, it still pops up with an alert message "You are about to log in to 'directory' using Username. Continue?" Is there a way to password protect a directory with just PHP? Protecting .php files is not the issue, it's various PDF and image files I need to protect. Thanks for any insight. Andrew Quote Link to comment https://forums.phpfreaks.com/topic/199260-password-protect-a-directory-with-php/ Share on other sites More sharing options...
oni-kun Posted April 21, 2010 Share Posted April 21, 2010 Is there a way to password protect a directory with just PHP? No, But there is with Apache. Quote Link to comment https://forums.phpfreaks.com/topic/199260-password-protect-a-directory-with-php/#findComment-1045826 Share on other sites More sharing options...
PFMaBiSmAd Posted April 21, 2010 Share Posted April 21, 2010 It sounds like you need to put the files into a folder that only php has access to (i.e. either put the folder outside your document root folder or deny all http requests to the files in the folder) and then dynamically output the files using a .php script. The .php script then checks if the current visitor is logged in before outputting the correct content type header followed by the contents of the correct file (assuming you want the file to open in the browser) and/or perform a 'force download', where the download dialog box is presented to allow the visitor to download and save the file on their system. Quote Link to comment https://forums.phpfreaks.com/topic/199260-password-protect-a-directory-with-php/#findComment-1045833 Share on other sites More sharing options...
AndrewJ1313 Posted April 23, 2010 Author Share Posted April 23, 2010 Thanks, PFMaBiSmAd - that did the trick. I knew I was over thinking it Quote Link to comment https://forums.phpfreaks.com/topic/199260-password-protect-a-directory-with-php/#findComment-1047314 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.