user name

This is a discussion on user name within the PHP Language forums, part of the PHP Programming Forums category; i am going through the process of password protecting a directory using ..htaccess and .htpasswd Is there a function to ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-21-2004
mickeyg
 
Posts: n/a
Default user name

i am going through the process of password protecting a directory using
..htaccess and .htpasswd
Is there a function to get the user name?

Thanks
Reply With Quote
  #2 (permalink)  
Old 10-22-2004
wheat
 
Posts: n/a
Default Re: user name

..htpasswd is a text file. The user name's in it are not encrypted. On
each line, you'll find a username, then a colon (:), and then the
encrypted password. Assuming you can read that file, you could run a
regular expression on it to parse out the usernames.

Why do you need them? Just curious. Generally, people either do their
authentication in PHP or via .htaccess. It seems you're trying to do
some combination of the two.

Reply With Quote
  #3 (permalink)  
Old 10-22-2004
 
Posts: n/a
Default Re: user name

"mickeyg" <meshulamtemp@yahoo.com> wrote in message news:PkVdd.6818$Ug4.4058@trndny01...
> i am going through the process of password protecting a directory using
> .htaccess and .htpasswd
> Is there a function to get the user name?


use the $_SERVER superglobal array:

$_['PHP_AUTH_USER']
When running under Apache as module doing HTTP authentication this variable is set to the username provided by the user.

$_['PHP_AUTH_PW']

When running under Apache as module doing HTTP authentication this variable is set to the password provided by the user.

http://us2.php.net/manual/en/reserve...riables.server

____________________________________
Wil Moore III, MCP | Integrations Specialist | Assistant Webmaster

Reply With Quote
  #4 (permalink)  
Old 10-22-2004
Pedro Graca
 
Posts: n/a
Default Re: user name

mickeyg wrote:
> i am going through the process of password protecting a directory using
> .htaccess and .htpasswd
> Is there a function to get the user name?


The $_SERVER superglobal array /may have/ the authentication elements:

<quote src="http://pt.php.net/manual/en/reserved.variables.php">
'PHP_AUTH_USER'
When running under Apache as module doing HTTP authentication
this variable is set to the username provided by the user.

'PHP_AUTH_PW'
When running under Apache as module doing HTTP authentication
this variable is set to the password provided by the user.

'AUTH_TYPE'
When running under Apache as module doing HTTP authenticated this
variable is set to the authentication type.
</quote>
--
USENET would be a better place if everybody read:
http://www.expita.com/nomime.html
http://www.netmeister.org/news/learn2quote2.html
http://www.catb.org/~esr/faqs/smart-questions.html
Reply With Quote
  #5 (permalink)  
Old 10-22-2004
sathia
 
Posts: n/a
Default Re: user name


phpinfo();


||

$_SERVER['PHP_AUTH_USER']

$_SERVER['PHP_AUTH_PASS'] // not sure

--
Sat_
Reply With Quote
  #6 (permalink)  
Old 10-22-2004
Gordon Burditt
 
Posts: n/a
Default Re: user name

>.htpasswd is a text file. The user name's in it are not encrypted. On
>each line, you'll find a username, then a colon (:), and then the
>encrypted password. Assuming you can read that file, you could run a
>regular expression on it to parse out the usernames.


I believe the OP wants the user name of the user accessing the page
this time, not all of them.

To further complicate things, there is no guarantee that the .htpasswd
file is in *THIS* directory.

>Why do you need them? Just curious. Generally, people either do their
>authentication in PHP or via .htaccess. It seems you're trying to do
>some combination of the two.


It is perfectly reasonable to have a restricted-access page, and further
let the page use the user name of the person accessing it, for
various purposes:

- Logging who did what.
- Using preferences individual to each user.
- Granting privileges individual to each user (determined, say, from
looking in a database or even hardcoded into the script).

Sometimes it is convenient to let Apache do the authentication (browsers manage
to store authentication info so you can come back at any time without needing
sessions or other such stuff. If your security policy isn't worried about
logins with no timeouts or unattended computers, this is great.) and then
let PHP hand out individual privileges based on WHO logged in.

The authenticated user shows up in $_SERVER['REMOTE_USER'] from Apache.
PHP also puts the user in $_SERVER['PHP_AUTH_USER'] and the password
in $_SERVER['PHP_AUTH_PW'] .

Gordon L. Burditt
Reply With Quote
  #7 (permalink)  
Old 10-22-2004
mickeyg
 
Posts: n/a
Default Re: user name

Thank you this is what I was looking for
Reply With Quote
  #8 (permalink)  
Old 10-22-2004
wheat
 
Posts: n/a
Default Re: user name

Gordon,

Thanks for the info. I didn't know that the username and password
provided during the .htaccess authentication process were availible to
PHP through server variables. Thanks for explaining their use.

Reply With Quote
  #9 (permalink)  
Old 10-22-2004
Shawn Wilson
 
Posts: n/a
Default Re: user name

Gordon Burditt wrote:
>
> >.htpasswd is a text file. The user name's in it are not encrypted. On
> >each line, you'll find a username, then a colon (:), and then the
> >encrypted password. Assuming you can read that file, you could run a
> >regular expression on it to parse out the usernames.

>
> I believe the OP wants the user name of the user accessing the page
> this time, not all of them.
>
> To further complicate things, there is no guarantee that the .htpasswd
> file is in *THIS* directory.
>
> >Why do you need them? Just curious. Generally, people either do their
> >authentication in PHP or via .htaccess. It seems you're trying to do
> >some combination of the two.

>
> It is perfectly reasonable to have a restricted-access page, and further
> let the page use the user name of the person accessing it, for
> various purposes:
>
> - Logging who did what.
> - Using preferences individual to each user.
> - Granting privileges individual to each user (determined, say, from
> looking in a database or even hardcoded into the script).
>
> Sometimes it is convenient to let Apache do the authentication (browsers manage
> to store authentication info so you can come back at any time without needing
> sessions or other such stuff. If your security policy isn't worried about
> logins with no timeouts or unattended computers, this is great.) and then
> let PHP hand out individual privileges based on WHO logged in.
>
> The authenticated user shows up in $_SERVER['REMOTE_USER'] from Apache.
> PHP also puts the user in $_SERVER['PHP_AUTH_USER'] and the password
> in $_SERVER['PHP_AUTH_PW'] .


I like to do this for the priveleges and logging you mentioned and also peace of
mind - I know that, if I ever accidentally overwrite the .htaccess and don't
notice, nobody will be able to wander on in and screw everything up.

Shawn

--
Shawn Wilson
shawn@glassgiant.com
http://www.glassgiant.com
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 08:19 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0