Jump to content

Recommended Posts

Posted

I get the following error when trying to do some simple HTTP authentication in a PHP script. I've never seen this before, and I can't find anything about it in the PHP manual. Any help would be appreciated. Thanks.

 

Warning: Cannot modify header information - headers already sent by (output started at /home/vphmubkc/public_html/timesheet/index.php:18) in /home/vphmubkc/public_html/timesheet/index.php on line 30

Posted

Welcome to the forums, vphmubkc! :lol:

 

At line 18 in your script, there is some statement that is sending actual content to the browser (echo, print, content or HTML outside of <?php ... ?> tags, etc.). This triggers all HTTP headers to be automatically sent, as the HTTP headers must all be sent before any content or HTML is sent to the browser.

 

At line 30 of your script, there is a function that is trying to add or modify the HTTP headers (probably header() ). Since all HTTP headers were already sent to the browser at line 18 of your script (along with whatever content or HTML was output), the HTTP headers can no longer be added to or modified, and this triggers the PHP error message you're seeing.

 

Hope this helps...

Posted
Nevermind, Davids answer was better sounding than mine.

Sorry! :)

 

I get the following error when trying to do some simple HTTP authentication in a PHP script.  I've never seen this before, and I can't find anything about it in the PHP manual.

I found this FAQ in the PHP manual that is probably most applicable to your issue:

6.  I get the message 'Warning: Cannot send session cookie - headers already sent...' or 'Cannot add header information - headers already sent...'.

 

The functions header(), setcookie(), and the session functions need to add headers to the output stream but headers can only be sent before all other content. There can be no output before using these functions, output such as HTML. The function headers_sent() will check if your script has already sent headers and see also the Output Control functions.

Even though your error is 'Cannot modify header information' rather than 'Cannot add header information', this FAQ answer is still applicable.

 

I have done the same thing by just having a space at the head of a script bfore going into php.

It could be simply a blank line or space, but whatever it is, it's at line 18, rather than at the beginning or end of the script. A couple of examples of what could cause this error:

>17: ?>
18:
19: <?php

>18: ?> <?php

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...