CarbonCopy Posted July 22, 2009 Share Posted July 22, 2009 I need to password protect a directory, put instead of apache based methods (.htaccess) i would like to use PHP. I don't care if it is PHP and a combination of .htaccess or anything else. I've already tried numerous approaches, and I am out of ideas, unless anyone can figure out how to make .htaccess files parse php code inside of them . Also, don't want a hack job like inserting php code inside every file, because that would be stupid. Right now I am trying to use .htaccess to redirect to a index.php which checks authentication then allows the user to proceed to the file. Any ideas with this? Link to comment https://forums.phpfreaks.com/topic/166885-password-protect-a-directory-with-php/ Share on other sites More sharing options...
ldougherty Posted July 22, 2009 Share Posted July 22, 2009 Well you could check sessions on your index page for that directory and if the session doesn't exist then prompt for a password. This of course would require you to write a full backend that would store user login information and what not. I believe the much easier idea would be to have php create/write to the .htaccess and .htpasswd files. Just use PHP functions to create the file(s) if they do not exist and if they do exist use the exec function to execute shell commands via script. Link to comment https://forums.phpfreaks.com/topic/166885-password-protect-a-directory-with-php/#findComment-879930 Share on other sites More sharing options...
CarbonCopy Posted July 22, 2009 Author Share Posted July 22, 2009 What could I write to the htaccess files that would allow the logged in user to access the files, but not anyone else? Can't user IP addresses, but I could try sending the login info in the headers. Any ideas? Link to comment https://forums.phpfreaks.com/topic/166885-password-protect-a-directory-with-php/#findComment-880257 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.