Cannot add header information...
| From: | Per Waagen | Date: | Thu, 22 Nov 2001 10:19:57 +0000 |
| Subject: | Cannot add header information... | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-75491@lists.php.net to get a copy of this message | ||
Need some help here, Im getting this error:
Warning: Cannot add header information - headers already sent by (output
started at /home/p/pe/perphp/public_html/login.php:4) in
/home/p/pe/perphp/public_html/login.php on line 44
...while trying to run the following .PHP code on my server. Any ideas why
this doesnt work?
(Im trying to setup user authentication and found this on the Webmonkey
site)
All tips are appreciated!!
<HTML><HEAD><TITLE>dummy</TITLE></HEAD>
<BODY>
<?php
// File Name: auth02.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;
} else if (isset($PHP_AUTH_USER)) {
if (($PHP_AUTH_USER != "admin") || ($PHP_AUTH_PW != "abc123")) {
header('WWW-Authenticate: Basic realm="My Private Stuff"');
header('HTTP/1.0 401 Unauthorized');
echo 'Authorization Required.';
exit;
} else {
echo "
<P>You're authorized!</p>
";
}
}
?>
</BODY>
</HTML>