Question

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
ondrovic
Forum Newbie
Posts: 8
Joined: Fri Jan 31, 2003 1:50 pm

Question

Post by ondrovic »

i have this but its doing this

Code: Select all

<? 
$PHP_AUTH_USER = $_SERVER&#1111;'PHP_AUTH_USER']; 
$PHP_AUTH_PW = $_SERVER&#1111;'PHP_AUTH_PW']; 
if(!$PHP_AUTH_USER || !$PHP_AUTH_PW) 
&#123; 
header('WWW-Authenticate: Basic realm="Admin"'); 
header('HTTP/1.0 401 Unathorized'); 
echo "Authorization Required."; 
exit; 
&#125; 
else 
&#123; 
if (($PHP_AUTH_USER=="user") && ($PHP_AUTH_PW=="pass")) 
&#123; 

echo "login successful"; 
&#125; 

else 
&#123; 
echo "Login failed"; 
&#125; 
&#125; 

?>
Notice: Undefined index: PHP_AUTH_USER in C:\Program Files\Apache Group\Apache2\htdocs\basic.php on line 2

Notice: Undefined index: PHP_AUTH_PW in C:\Program Files\Apache Group\Apache2\htdocs\basic.php on line 3

Warning: Cannot add header information - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\htdocs\basic.php:2) in C:\Program Files\Apache Group\Apache2\htdocs\basic.php on line 6

Warning: Cannot add header information - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\htdocs\basic.php:2) in C:\Program Files\Apache Group\Apache2\htdocs\basic.php on line 7
Authorization Required.
i think its because i have php running as cgi not a module so how can i setup php to run as a module?

i have the latest version of php mysql and apache http server

thanks for the help
User avatar
redcircle
Forum Commoner
Posts: 43
Joined: Fri Jan 31, 2003 8:47 pm
Location: michigan, usa

Post by redcircle »

Code: Select all

<? 
if(isset($_SERVER&#1111;'PHP_AUTH_USER']))
    $PHP_AUTH_USER = $_SERVER&#1111;'PHP_AUTH_USER'];
else
    $PHP_AUTH_USER = '';

if(isset($_SERVER&#1111;'PHP_AUTH_PW']))
   $PHP_AUTH_PW = $_SERVER&#1111;'PHP_AUTH_PW'];
else
   $PHP_AUTH_PW = ''; 

 
if(!$PHP_AUTH_USER || !$PHP_AUTH_PW) 
&#123; 
header('WWW-Authenticate: Basic realm="Admin"'); 
header('HTTP/1.0 401 Unathorized'); 
echo "Authorization Required."; 
exit; 
&#125; 
else 
&#123; 
if (($PHP_AUTH_USER=="user") && ($PHP_AUTH_PW=="pass")) 
&#123; 

echo "login successful"; 
&#125; 

else 
&#123; 
echo "Login failed"; 
&#125; 
&#125; 

?>
or you can use

Code: Select all

<?php
if(!isset($_SERVER&#1111;'PHP_AUTH_USER']) || !isset($_SERVER&#1111;'PHP_AUTH_PW'])) 
&#123; 
header('WWW-Authenticate: Basic realm="Admin"'); 
header('HTTP/1.0 401 Unathorized'); 
echo "Authorization Required."; 
exit; 
&#125; 
else 
&#123; 
if (($PHP_AUTH_USER=="user") && ($PHP_AUTH_PW=="pass")) 
&#123; 

echo "login successful"; 
&#125; 

else 
&#123; 
echo "Login failed"; 
&#125; 
&#125; 

?>

your last option would be to turn off error notices in the php.ini.
ondrovic
Forum Newbie
Posts: 8
Joined: Fri Jan 31, 2003 1:50 pm

Post by ondrovic »

cool cool thanks for the help
now i got one more quick question how do i specify multiple username and password using the first script and how do i make it work to with members.html?

Again thanks
Post Reply