Quick question about PHP_AUTH_USER

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Linkjames
Forum Commoner
Posts: 90
Joined: Tue Sep 16, 2003 8:39 am

Quick question about PHP_AUTH_USER

Post by Linkjames »

I have a PHP file that contains the following

Code: Select all

<?php 
     
if ((!isset( $PHP_AUTH_USER )) || (!isset($PHP_AUTH_PW))) { 

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

} else { 

    echo "You entered $PHP_AUTH_USER for a username.<BR>"; 
    echo "You entered $PHP_AUTH_PW for a password.<BR>"; 

} 

?>
When loaded, it pops up the dialog box asking for username and password. As you can see, there isn't one. The script should let you in as long as you enter somthing. But this keeps popping up the box every time you click ok.
Any ideas? I have checked it with 2 browsers, and run it from 2 servers, and still the same problem.

Help

cheers - James
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

as of php 4.1 these values are elements of the superglobal array $_SERVER and as of php 4.2 they are not registered in the global scope by default.

see also:
Sticky: Before Post Read: Concerning Passing Variables in PHP 4.2+
php manual: Predefined Variables
Post Reply