PDA

View Full Version : Getting the username authenticated by .htaccess


petemod
03-15-2007, 06:53 AM
Hi,

How can I somehow get the username that was authenticated when someone logged in. Is just basic .htaccess authentication, I just somehow need to get the username that was provided.
Thanks

mlseim
03-15-2007, 08:38 PM
.htaccess is for protecting directories or files (access limitations).

If you have some Perl or PHP script somewhere that people are logging into,
such as a forum like this, a blog ... (you didn't say how people are
logging in), a session or a cookie is set, depending on the script. That
is what stores that information.

Or perhaps you don't mean "logging in", but visiting the site?

You'll have to elaborate some more.

petemod
03-16-2007, 01:28 AM
Sorry,
I don't have any PHP/Perl script. The directory with the cgi script has been protected through a .htaccess file in that directory. Which has:
AuthType Basic
AuthName "Administration Area"
AuthUserFile "/home/username/.htpasswds/passwd"
require valid-user

Sorry for confusion.

Thanks

mlseim
03-16-2007, 03:47 AM
You can look for the ".htpasswds" file, but I'm guessing it's encrypted.

I think you need to contact the webhost or the server I.T. person
to reset this, or erase it so you can create a new .htaccess file.

If you can access the directory with an FTP program, did you try
deleting the .htaccess file?

petemod
03-16-2007, 10:09 AM
You can look for the ".htpasswds" file, but I'm guessing it's encrypted.

I think you need to contact the webhost or the server I.T. person
to reset this, or erase it so you can create a new .htaccess file.

If you can access the directory with an FTP program, did you try
deleting the .htaccess file?

I think you are misunderstanding me. I have access to the .htaccess. I will try and explain a bit better.

When a user goes to xyz directory they need to enter a username and password to gain access. This is controlled by the .htaccess and htpassword file.
What I would like is the ability to use the username supplied by the user in a cgi script. A simple example would be that I want to be able to print "Welcome $username";

I have been looking for a solution for a while now but have never found anything.

Any ideas?

bazz
03-16-2007, 01:25 PM
Hi,

By the sounds of things you want to do what I tried a fortnight ago (Blimey, it was about 6 weeks ago :eek: ). I shall try to find the thread but, what you are looking for is the capability of catching the username when they log in and use it on one or more subsequent web pages - correct?

if so, then you'd be better to use a login script with a MySQL backend. Probaly you'll find one in the php forum or even MySQL. I haven't actually got around to doing it yet for myself or you could see my script.

Here's the earlier thread.
(http://www.codingforums.com/showthread.php?t=108816)

hth,

Bazz

mlseim
03-16-2007, 01:58 PM
Pete ... oh I see now.

Myself, like Bazz would rather use a PHP/MySQL membership script
to control directory and file access. I only use .htaccess to protect
data file directories (photo galleries, MP3, text files, etc).

The best thing about using a membership script is that you can access
the session variables for any other pages you have while the "member"
navigates around your site.

Sorry after all that, I don't really have an answer.

macchisp
03-20-2007, 04:48 PM
I know with CGI, there are environmental variables that hold this information into variables.

Since you're not working with perl/cgi, I don't know if this will help but check out this page (http://www.perlfect.com/articles/cgi_env.shtml) to get an idea of what to do.

$ENV{'REMOTE_USER'} will get the user id.

Hope this puts you on the right path.