Results 1 to 11 of 11

Thread: HTTP authentication just doesn't work.

  1. #1

    Thread Starter
    Fanatic Member scr0p's Avatar
    Join Date
    Oct 2002
    Location
    VA
    Posts
    720

    HTTP authentication just doesn't work.

    when I put a authentication script, a dialog box pops up and keeps asking for name/pw, ANYTHING I put (correct or wrong) it keeps asking, and after 3-4 tries it says "requires authorisation", I copied the code from php.net and from other sites, still doesnt work, do I need to "enable" this from my browser or something?
    This piece of code, keeps asking me for name/pw.. even tho it doesnt even validate them.
    Code:
    <?php 
    
    	// File Name: auth01.php
    	// Check to see if $PHP_AUTH_USER already contains info
    
    	if (!isset($PHP_AUTH_USER)) {
    
    		// If empty, send header causing dialog box to appear
    		header('WWW-Authenticate: Basic realm="My Private Stuff"');
    		header('HTTP/1.0 401 Unauthorized');
    		echo 'Authorization Required.';
    		exit;
    	}
    
    		// If not empty, display values for variables
    
    	else {
    
    		echo "
    		<P>You have entered this username: $PHP_AUTH_USER<br>
    		You have entered this password: $PHP_AUTH_PW<br>
    		The authorization type is: $PHP_AUTH_TYPE</p>
    		";
    
    	}
    
    ?>
    or this:
    Code:
    <?php
    	header("WWW-Authenticate: Basic realm=\"System Information\""); 
    	header("HTTP/1.0 401 Unauthorized");
    	print $_SERVER['REMOTE_USER'];
    
    if ( (!isset($_SERVER['$PHP_AUTH_USER'])) || (!isset($_SERVER['$PHP_AUTH_PW'])) )
    {
        header('WWW-Authenticate: Basic realm="Private Area"');
        header("HTTP/1.1 401 Unauthorized");
        print "This page requires authorisation.";
    	print $_SERVER['$PHP_AUTH_USER'];
    	print $_SERVER['$PHP_AUTH_PW'];
        exit();
    }
    else
    {
        print "You're through to the secret page, was the effort worth it?";
    }
    ?>
    
    <html>
    <head>
    <title> .:Header password ****:. </title>
    </head>
    <body>
    </body>
    </html>
    Last edited by scr0p; May 4th, 2003 at 08:25 PM.
    asdf

  2. #2
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    use the second one. also it has problems as well

    PHP Code:
    if ( (!isset($_SERVER['$PHP_AUTH_USER'])) || (!isset($_SERVER['$PHP_AUTH_PW'])) 
    // should be

    if ( (!isset($_SERVER['PHP_AUTH_USER'])) || (!isset($_SERVER['PHP_AUTH_PW'])) 

    //and 

    print $_SERVER['$PHP_AUTH_USER'];
    print 
    $_SERVER['$PHP_AUTH_PW'];

    //should be

    print $_SERVER['PHP_AUTH_USER'];
    print 
    $_SERVER['PHP_AUTH_PW']; 

  3. #3

    Thread Starter
    Fanatic Member scr0p's Avatar
    Join Date
    Oct 2002
    Location
    VA
    Posts
    720
    It doesn't have to be, on my host www.team-od.com, the 2 scripts I had before the modification worked. I will try them like you said right now on my own machine.
    asdf

  4. #4

    Thread Starter
    Fanatic Member scr0p's Avatar
    Join Date
    Oct 2002
    Location
    VA
    Posts
    720
    doesn't work.. I can write my scripts and upload to the host with no problems, the problem is somewhere on my machine.
    asdf

  5. #5
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    Originally posted by scr0p
    It doesn't have to be, on my host www.team-od.com, the 2 scripts I had before the modification worked. I will try them like you said right now on my own machine.
    what do you mean? doesn't have to be??

    there is no such varuiable as

    $_SERVER['$PHP_AUTH_USER'];

    read the manual. if you have that then you are doing it wrong.

    if the problem is on your machin ethan are you running the ISAPI module? or are you in cgi mode?

  6. #6

    Thread Starter
    Fanatic Member scr0p's Avatar
    Join Date
    Oct 2002
    Location
    VA
    Posts
    720
    er, thats what I meant, without the $, but I meant it doesnt have to be with the $_SERVER, i can also do echo $PHP_AUTH_USER, what is the diff between CGI and ISAP? how do I check what I have installed?
    asdf

  7. #7
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    it doesn't depend on that. it can care less if you installed it as cgi or ISAPI, it depends on the register_globals being off.

    bu tall this can be found in the phpinfo();

    <?php
    phpinfo();
    ?>

    add that to a page and run it. it will tell you how and what is installed with php.

    this,

    header('WWW-Authenticate: Basic realm="My Private Stuff"');
    header('HTTP/1.0 401 Unauthorized');
    echo 'Authorization Required.';

    will not run in cgi mode

  8. #8

    Thread Starter
    Fanatic Member scr0p's Avatar
    Join Date
    Oct 2002
    Location
    VA
    Posts
    720
    Register globals is on.
    asdf

  9. #9
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    globals ON use this $PHP_AUTH_USER

    globals OFF use this $_SERVER["PHP_AUTH_USER"]

    so what part doesn't work?

  10. #10

    Thread Starter
    Fanatic Member scr0p's Avatar
    Join Date
    Oct 2002
    Location
    VA
    Posts
    720
    When I put a authentication script, a dialog box pops up and keeps asking for name/pw, ANYTHING I put (correct or wrong) it keeps asking, and after 3-4 tries it says "requires authorisation".. Its probably a problem with something else on my PC, Apache or something, not with PHP.
    asdf

  11. #11
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    the first piece of code should work. the second one needs to be changed to this
    PHP Code:
    <?php
    if ( (!isset($_SERVER['$PHP_AUTH_USER'])) || (!isset($_SERVER['$PHP_AUTH_PW'])) )
    {
        
    header('WWW-Authenticate: Basic realm="Private Area"');
        
    header("HTTP/1.1 401 Unauthorized");
        print 
    "This page requires authorisation.";
        print 
    $_SERVER['PHP_AUTH_USER'];
        print 
    $_SERVER['PHP_AUTH_PW'];
        exit();
    }
    else
    {
        print 
    "You're through to the secret page, was the effort worth it?";
    }
    ?>
    look at the difference of the two scripts. you have the "WWW-Authenticate" at the very fist of the script and it was getting asked to run everytime.

Posting Permissions

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



Click Here to Expand Forum to Full Width