Hi everyone,
I'm new to PHP (and the forum), so I apologize if this is a ridiculously simple task to accomplish in PHP.
I'm trying to have a simple password-protected section of my site, using a browser-produced login and password prompt. I found this script online, and placed it at the start of a sample file, before any HTML commands:
<?php
$auth = 0;
$username="USER";
$password="PASSWORD";
if (($PHP_AUTH_USER == $username ) && ($PHP_AUTH_PW == "5rrybsw2")) $auth = 1;
if ( $auth != 1 ) {
header("WWW-Authenticate: Basic realm="Authorization Required!"");
header("HTTP/1.0 401 Unauthorized");
echo 'Authorization Required!';
exit;
}
?>
<HTML>
<BODY>
Hello world!
</BODY>
</HTML>
However, when I upload it to my site, I get the message:
Parse error: parse error, unexpected T_STRING in domainname.com/tester.php on line 5.
But when I comment out line 5 (the header("WWW-Authenticate. . . line), the script gives no error and goes directly to the echo statement, without creating a login prompt.
Is there something wrong with my syntax? If not, is it possible that my server does not support the WWW-Authenticate feature? I've heard that this command is browser-specific, so I'm not sure why it wouldn't work in this application. Can somebody offer some assistance?
Matt