Re: HTML tags in auth.php script

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> Hello every one. I am still learning how PHP works. Can some one answer
> this
> for me please.
>
> This piece of code here works fine ONLY without the HTML tags  (The
> first line and the last lines in the code).
> The moment I add these lines I get the following error:  (By the way I
> don't get these errors if I execute this script on UNIX)
>
> Warning: Cannot add header information - headers already sent by (output
>       started at c:\phpdev\www\public\auth.php:2) in
>       c:\phpdev\www\public\auth.php on line 4
>
>       Warning: Cannot add header information - headers already sent by
>       (output started at c:\phpdev\www\public\auth.php:2) in
>       c:\phpdev\www\public\auth.php on line 5
>       Text to send if user hits Cancel button
>
> Basically what I am trying to do is to add
> this line to get a background image for this page "auth.php"  in my
> images folder.
> <body background=\"../pics/creme_swirl.jpg\"  text=\"green\"
> link=\"blue\" alink=\"red\" vlink=\"red\">
>
>
> <HTML>
> <?php
>  if (!isset($_SERVER['PHP_AUTH_USER'])) {
>    header('WWW-Authenticate: Basic realm="My Realm"');
>    header('HTTP/1.0 401 Unauthorized');
>    echo 'Text to send if user hits Cancel button';
>    exit;
>  } else {
>    echo "<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>";
>    echo "<p>You entered {$_SERVER['PHP_AUTH_PW']} as your
> password.</p>";
>  }
> ?>
> </HTML>

Absolutely anything outside of the <?php and ?> tags is considered output to
the browser. In order to use the header() function, you can't have any
output before the call to header().

If you want to add that text, then add it in where there is already output
in the file. Add it to the echo for the "Text to send if ... " or where your
"Hello ... " message is at.

---John Holmes...


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux