Jump to content

Password protect a directory..... with php


CarbonCopy

Recommended Posts

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 :D. 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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.