Development 1&1 and HTTP Auth

Discussion in 'Software' started by ChriX, 1 Aug 2005.

  1. ChriX

    ChriX ^

    Joined:
    30 Aug 2001
    Posts:
    2,650
    Likes Received:
    4
    I'm having a problem when using 1&1 hosting, where I cannot get HTTP Authentication to work. The following is a simple bit of code from php.net that should echo the username and password you input. This works fine on my home dev server, but when I use it on 1&1 it just keeps the username/password dialog coming up over and over until you press cancel.

    PHP:
     if ($_SERVER['PHP_AUTH_USER'] == "") {
       
    header('WWW-Authenticate: Basic realm="My Realm"');
       
    header('HTTP/1.0 401 Unauthorized');
       echo 
    'Text to send if user hits Cancel button';
       exit;
      } else {
       echo 
    "<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>";
       echo 
    "<p>You entered {$_SERVER['PHP_AUTH_PW']} as your password.</p>";
      }
    I was wondering if anyone else had come across the same problem, and if so how did you get around it?

    Ta. :D
     
  2. RTT

    RTT #parp

    Joined:
    12 Mar 2001
    Posts:
    14,120
    Likes Received:
    74
    This means that 1&1 are running PHP in safe mode. I think you can use something like $_SERVER['REMOTE_USER'] instead but don't quote me on that ;)
     
  3. Bruno_me

    Bruno_me Fake-ad‎min

    Joined:
    30 Mar 2003
    Posts:
    1,136
    Likes Received:
    1
    safe_mode Off

    that's on my 1and1 account...
     
  4. ChriX

    ChriX ^

    Joined:
    30 Aug 2001
    Posts:
    2,650
    Likes Received:
    4
    Finally got a reply from them and they said it's because they run PHP as a cgi instead of as an Apache module. Oh well...
     
  5. TheAnimus

    TheAnimus Banned

    Joined:
    25 Dec 2003
    Posts:
    3,214
    Likes Received:
    8
    normally when its as CGI istead of apache module, its slower, but run in unsafe mode?

    With my first PHP enabled ISP (Freedom2Surf) i had to use a CGI entry point to avoid safemode? Do you think thats what they ment.

    if its CGI mode at present you'll have to have like #!/bin/php or something at the top of each file.
     
  6. ChriX

    ChriX ^

    Joined:
    30 Aug 2001
    Posts:
    2,650
    Likes Received:
    4
     
  7. TheAnimus

    TheAnimus Banned

    Joined:
    25 Dec 2003
    Posts:
    3,214
    Likes Received:
    8
    hmm i think you could work around this, if you have a .htaccess you can make it parse that, but i can't remeber hwo you dupe it into parsing a PHP file. It can be done.

    Another way would be to force apache to always show the auth box, this can be done with a .htaccess again, that way, it will let them run the PHP script with whatever you type, but i think you can still get the variables. I think.
     

Share This Page