Forum Moderators: coopster

Message Too Old, No Replies

Php_auth

Banging • Head • Against • Wall

         

lZakl

2:10 am on Jun 7, 2005 (gmt 0)

10+ Year Member



I don't understand the problem I am having.. I am getting the dreaded

Warning: Cannot modify header information - headers already sent by (output started at /usr/lib/php/inc_test.inc:2) in /our/web/dir/index.php on line 15

... blah blah blah message. I know what the problem is, but I don't. Let me explain.

The following code works WITHOUT the include(); Once the include is ... well .. included, I get the warning. I know my include works, I have tested it in other scipts. the <?php is all the way at the top like it should be with no trailing spaces etc.

So now that I know that my include is causing this error, I need to know what about my include is so negative. In other words "why?".

[b]index.php -->[/b]

<?php
session_start();

include('inc_test.inc');

if (!isset($_SERVER['PHP_AUTH_USER']))
{
header('WWW-Authenticate: Basic realm=\"Advertisers\"');
header('HTTP/1.0 401 Unauthorized');
echo 'Authorization Required.';
exit;
}
else if (isset($_SERVER['PHP_AUTH_USER']))
{

if (($_SERVER['PHP_AUTH_USER']!= "admin") ¦¦ ($_SERVER['PHP_AUTH_PW']!= $pass)) [b]// Line 15 [/b]
{
header('WWW-Authenticate: Basic realm="Advertisers"');
header('HTTP/1.0 401 Unauthorized');
echo 'Authorization Required.';
exit;
}
}
?>

[b]inc_test.inc -->[/b]

<?php
$MyArray[] = "element1";
$MyArray[] = "element2";
$MyArray[] = "element3";
$MyArray[] = "element4";
print "Testing ... I have been included!";
?>

Thanks ...

-- Zak

lZakl

2:26 am on Jun 7, 2005 (gmt 0)

10+ Year Member



Should have known that was going to happen! That I was going to figure it out right after I was done posting!

My "test" statement in the include was causing it.. print statement before the cookie ... sheesh!

-- Zak

jatar_k

4:21 pm on Jun 7, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



often just laying it out for other people to see helps us organize it and figure it out

hehe, posting is the best medicine ;)