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? Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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.