Jump to content

Cannot modify header


cesarcesar

Recommended Posts

I have a page I'm calling headers on. I'm getting the error

PHP Warning:  Cannot modify header information - headers already sent by

So i use headers_sent() to see where the issue is. It says line 1. At line 1 I only have a <?php on the line with NO white space before it. more test.. same error. I then remove everything and only have one line of code with a header(Location:http://www.blabla.com) on line 1. Again no white space before or after PHP. Still the same error.

 

Why is this happening? Why are my headers failing? Thanks much.

 

 

Link to comment
Share on other sites

you can solve it without ob_start().

 

Look at this example:

<html>
   <head>
       <title>my page</title>
   </head>
<?php header('Location: page2.html'); ?>
</html>

This will raise the error because the html-block is already sent.

To correct that, easiely put that header to the very top of the code:

<?php header('Location: page2.html');
exit; //that's important to stop loading the rest of the page.
?>
<head>
<!-- rest of the html -->

 

Also look if there is no space before you php-block.

Link to comment
Share on other sites

Found the problem. Thanks to all those that helped.

 

Basically there was some type of invisible character in the beginning of my file. I copied all of the file but the first and last character, then pasted into a new doc. Saved over the old doc and it works!

 

I'm using EditPlus3 text editor in case anyone knows why this invisible char was added.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.