Forum Moderators: phranque

Message Too Old, No Replies

2 different usernames and password in one .htaccess

possible?

         

someone

12:17 am on Jan 6, 2006 (gmt 0)

10+ Year Member



I have a directory and let's call it "staff". Within "staff", I have two files that required password protected and let's call them a.php and b.php. a.php and b.php should have different username and password. But since they are in the same directory and I can only put one .htaccess in the directory. How do I make their username different since the .htaccess info applies to all the files in the directory? How do I make sure that when people go to a.php, they will have to enter a different username and password than when they go to b.php?

skyeflye

12:52 am on Jan 6, 2006 (gmt 0)

10+ Year Member



Would it perhaps be easier if you setup your directory structure like this:

/staff/a/index.php
/staff/b/index.php

Then you could have two separate .htaccess files (one in the "a" directory and one in the "b" directory). And you could also simply provide the URLs to users as:

http://www.example.com/files/a/
and
http://www.example.com/files/b/

That may not be possible for some specific reason in yoru case, but perhaps it would simplify your situation with regard to the .htaccess files.

Although, there probably is some way to use a single .htaccess file to "protect" two files being in the same directory but with different login credentials for each file. I just don't know how to do that (sorry).

sonjay

2:17 am on Jan 6, 2006 (gmt 0)

10+ Year Member



Yes you can do it just the way you want. You just use the <Files> directive in your .htaccess or httpd.conf file:

<Files a.php>
Require user usernamea
</Files>

<Files b.php>
Require user usernameb
</Files>

You can check the documentation at apache.org for full details.

someone

4:57 pm on Jan 6, 2006 (gmt 0)

10+ Year Member



Got it, thanks guys for your idea and answer!