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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.