SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Question accessing .htpasswd login from PHP

    On my latest client's site, I have a subdomain dedicated to the administration. .htaccess is used to authenticate any user on that subdomain, with the .htpasswd above the root directory. My client has requested that there should be two accounts to login to the admin side - One is for the content author, the other for the staff who can only view orders and modify products.

    Is there any way of accessing the username used to login to the site through PHP?

    For example, at the login popup box (.htaccess), if I enter the username "bob" (why should I use my imagination?), How could I access the username "bob" through PHP?

    Thanks guys,
    Jake Arkinstall
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  2. #2
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    for groups of users you can use AuthGroupFile
    my mobile portal
    ghiris.ro

  3. #3
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    $_SERVER

    'PHP_AUTH_DIGEST'
    When running under Apache as module doing Digest HTTP authentication this variable is set to the 'Authorization' header sent by the client (which you should then use to make the appropriate validation).

    'PHP_AUTH_USER'
    When running under Apache or IIS (ISAPI on PHP 5) as module doing HTTP authentication this variable is set to the username provided by the user.

    'PHP_AUTH_PW'
    When running under Apache or IIS (ISAPI on PHP 5) 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.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  4. #4
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Because I'm running on a Linux server, the above didn't work.

    However, by using print_r($_SERVER), I found that REMOTE_USER worked.

    Thanks for the direction.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  5. #5
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    The Linux server running Apache isn't it?

    Hmm I'm guessing PHP is running as CGI and not a module.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •