htaccess pw protection

C

chlori

Hello

I would like to use a .htaccess file for "protecting" a
directory. On a website (doesn't exist yet) there
should be a login form. Depending on who logs in, the
user should be directed to a seperate page.

Example:
If you use the login name "Robert" with password
"Pass", then you get to the page "intra/robert.html"...

Is it possible with .htaccess? How?
Any other/better/easier suggestions?
 
S

Simon

Hello
I would like to use a .htaccess file for "protecting" a directory. On a
website (doesn't exist yet) there should be a login form. Depending on
who logs in, the user should be directed to a seperate page.

Example:
If you use the login name "Robert" with password "Pass", then you get to
the page "intra/robert.html"...

Is it possible with .htaccess? How?
Any other/better/easier suggestions?
It is possible to do this using a combination of .htaccess and a CGI
script. The CGI script would have to be set as the directory's index
file (using the DirectoryIndex directive). Once the user has logged in,
they would be taken to the CGI script, which would take the user's login
name and use it to figure out which page the user should be redirected to.

Regards
Simon
Custom Net Hosting
http://www.customnethosting.com
 
C

chlori

Simon schrieb am 10.01.2005 04:50:
It is possible to do this using a combination of .htaccess and a CGI
script. The CGI script would have to be set as the directory's index
file (using the DirectoryIndex directive). Once the user has logged in,
they would be taken to the CGI script, which would take the user's login
name and use it to figure out which page the user should be redirected to.

Thanks for your answer. Do you have a link to a
tutorial or something like that?
 
S

Simon

Hello,
Thanks for your answer. Do you have a link to a tutorial or something
like that?

To set up the .htaccess and .htpasswd files, look at this:
http://www.he.net/faq/tutorials/htaccess/demo.html

(There are other tutorials around too - just do a search on Google for
..htpasswd)

Check with your web host to see what you should call the CGI script. To
set up the CGI, script, take a look at this:
http://experts.about.com/q/1045/3420327.htm

It includes a sample script that shows how to get the username and
redirect the user to the appropriate page.

Regards
Simon
Custom Net Hosting
http://www.customnethosting.com
 
C

chlori

Simon schrieb am 10.01.2005 10:04:
Check with your web host to see what you should call the CGI script. To
set up the CGI, script, take a look at this:
http://experts.about.com/q/1045/3420327.htm

It includes a sample script that shows how to get the username and
redirect the user to the appropriate page.

Thanks!

So I create a file called something.cgi (after I have
asked my web host how to call it) with this content
(nothing else?):


$baseurl = "http://www.mysite.com/members";
$htpasswd = ".htpasswd";

$myuser = $ENV{'REMOTE_USER'};

print "Location: $baseurl/$myuser/\n\n";


Is $baseurl the url of the page with the login form? Or
can it be anything if it contains a folder /$myuser/?

$myuser: If Robert logs in with "Robert", then $myuser
is "Robert" and the folder is called "Robert"...? Is
theis case sensitive?

What is $htpasswd used for in this script?
 
C

chlori

Simon schrieb am 10.01.2005 10:04:
Check with your web host to see what you should call the CGI script.

They say the CGI script has to be in the CGI folder and
needs the extension .pl or .cgi.

Do I then first have to redirect to the cgi script/folder?
 
S

Simon

Hi,
So I create a file called something.cgi (after I have asked my web host
how to call it) with this content (nothing else?):


$baseurl = "http://www.mysite.com/members";
$htpasswd = ".htpasswd";

$myuser = $ENV{'REMOTE_USER'};

print "Location: $baseurl/$myuser/\n\n";
That's right.
Is $baseurl the url of the page with the login form? Or can it be
anything if it contains a folder /$myuser/?
It can be anything if it contains /$myuser/
$myuser: If Robert logs in with "Robert", then $myuser is "Robert" and
the folder is called "Robert"...? Is theis case sensitive?
Yes, it's case sensitive. So Robert would be redirected to
$baseurl/Robert - if you have named the folder "robert" instead, you
will run into problems.
What is $htpasswd used for in this script?
I have no idea, and was wondering that myself.

Simon
 
S

Simon

Hi
Simon schrieb am 10.01.2005 10:04:



They say the CGI script has to be in the CGI folder and needs the
extension .pl or .cgi.

Do I then first have to redirect to the cgi script/folder?
You can get around this with the DirectoryIndex directive. Suppose that
you call the script something.cgi and upload it to your cgi-bin folder.
You want your users to go to http://www.example.com/members, enter their
user name, and be taken to their own page. You would edit the .htaccess
file for the /members directory and insert the following directive:
DirectoryIndex /cgi-bin/something.cgi

Regards
Simon
Custom Net Hosting
http://www.customnethosting.com
 
C

chlori

Simon schrieb am 10.01.2005 19:42:
You would edit the .htaccess
file for the /members directory and insert the following directive:
DirectoryIndex /cgi-bin/something.cgi

Thanks Simon!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top