Milonic provide full featured pull down web menus for some of the worlds largest companies
click here to see what it can do for you

Download Milonic DHTML Menu
Buy Milonic DHTML Menu

Back To Start Of Archive
Taken From The Forum: Help & Support for DHTML Menu Version 5+
Forum Topic: Click to view post
Last Updated: Saturday July 14 2012 - 06:07:11

Cannot modify header information - headers already sent


Poster: bobbitt
Dated: Friday April 3 2009 - 2:11:37 BST

Hi all,

I'm having a *small* problem with the menu... with every page view, I now get a "Cannot modify header information - headers already sent" warning. It doesn't affect the functionality, and isn't visible to my users, but it's filling up my error log pretty quickly.

I checked but could not find any header output calls in the menu script. (However when I exclude the menu, the warnings do not appear.) Anyone know where the header output may be coming from? Does the meny read or set cookies or anything like that?


Thanks
Mike

Re: Cannot modify header information - headers already sent


Poster: Ruth
Dated: Friday April 3 2009 - 4:09:08 BST

Hi,

As to the header problem, you will need to send us a link to the page so we can see what's going on. It sounds like something to do with the page, i.e. if you're using a template, or something like that.

Ruth

Re: Cannot modify header information - headers already sent


Poster: bobbitt
Dated: Friday April 3 2009 - 15:04:41 BST

Hi Ruth,

Thanks... the site in question is http://forums.army.ca/. The menu works fine so there's not much to see there, but in my erorrlog, every pave visit shows the "headers alraedy sent" message. Just wondering if the menu script tries to output any HTTP headers... if so I've probably already written out some HTML content, so the headers won't be sent.


Thanks
Mike

Re: Cannot modify header information - headers already sent


Poster: Ruth
Dated: Friday April 3 2009 - 18:28:27 BST

Hi,

It looks like it might be a security issue with regard to googleads. I get this message when I load a new page using the menu

Security Error: Content at
Code:
http://googleads.g.doubleclick.net/
may not load data from http://forums.army.ca/.

Now, I have to tell you this is beyond my knowledge level and I am only posting what I've found as to error and it might not have anything to do with the error log message you are getting. I am going to suggest that you file a support ticket for this since you need a level of help I cannot provide.

http://www.milonic.com/support/

When you fill the ticket, give them the same information about your error log and the link to the site. Hope you can get it figured out here.

By the way, I like that site, it really looks nice :)

Ruth

Re: Cannot modify header information - headers already sent


Poster: davebarnes
Dated: Thursday April 9 2009 - 23:22:26 BST

__at__ bobbitt,

I am not a PHP expert by any means. I think the errors that you are getting are related to something similar to:

Code:
<?php
  ob_start();  /* Start buffer so we can use header anywhere in the page  */
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>


If you have the ob_start, then the DOCTYPE must follow it and not precede it.

You need a PHP expert.

Re: Cannot modify header information - headers already sent


Poster: bobbitt
Dated: Friday April 10 2009 - 14:55:31 BST

Thanks Dave, that gives me an idea where to start looking! If I figure it out I'll post it here.


Cheers
Mike

Re: Cannot modify header information - headers already sent


Poster: bobbitt
Dated: Sunday May 10 2009 - 2:52:48 BST

A quick follow-up... I wish I had a solution to report, but unfortunately not yet. In fact I've been able to conclusively determine that the menu is the central to the issue. I recently discovered that my links program isn't working, for the same reason. When I click a link, I'm not redirected, and I see the familiar "PHP Notice: A session had already been started - ignoring session_start()" in my apache logs.

Here's a quick way to verify... this link should redirect you to the UN's home page:

http://milnet.ca/links/directory.php?jump=226

As you can see, it doesn't. What you can't see is that it generates the PHP notice mentioned above. If you call the same link but disable the menu*, it works:

http://milnet.ca/links/directory.php?ju ... hidemenu=1

Now that the problem has evolved into more than just log entries, I'm hoping I can resolve it. I guess my first question is, what does the PHP menu code do that writes to the HTTP header? Does it set a cookie? The code is rather obfuscated so I'm not really sure what to look for, but any assistance would be great! I think ultimately I either need to figure out a way to get the menu to write the header later in my page rendering, or leave the header "writable" for other scripts I run on the page. Has anyone seen a similar problem?


Thanks!
Mike

* Appending the 'hidemenu' variable to the URL changes just one thing: it does not include my menu's PHP script. (I'm using the PHP menu...)

Edit to add that I'm on 5.819.

Re: Cannot modify header information - headers already sent


Poster: bobbitt
Dated: Sunday February 7 2010 - 22:08:00 GMT

Hi All,

I'm now at 5.830 and still seeing the same problem. If I don't manually clean out the error logs on my forums, they grow without bound because of the header already sent messages. As a result, it's impossible to use the error logs to isolate any "real" problems. The problem is also still preventing my links directory from working at all.

I just got a renewal notice for the menu script... I'd love to keep using it, but unless I can find a solution to this issue, it's probably causing more challenges than I need right now.

Any help is appreciated!


Thanks
Mike

Re: Cannot modify header information - headers already sent


Poster: Andy
Dated: Monday February 8 2010 - 9:27:55 GMT

Hi Mike,

One thing that I can confirm is that it's not the menu causing the error, the menu is client side and has no way of accessing the headers - What it is, is your placement of menu code within your forum.

Can you please tell me how you are embedding the menu into your forum. It looks like phpBB but I'm not 100% sure on that.

I'm guessing that you've embedded the menu into one of the include files, can you please confirm which one and where.

I'm sure we'll get to the bottom of this.

Cheers,
Andy

Re: Cannot modify header information - headers already sent


Poster: bobbitt
Dated: Monday February 8 2010 - 13:03:49 GMT

Thanks Andy. It's a tricky problem because the menu alone won't generate the error, and the rest of my board without the menu won't generate the error. The moment I combine them, every pageload generates the error, so there's some interaction going on here.

My forums are SMF 2.0 RC2, and I've added the include for the menu in index.template.php, right after the opening <body> tag. I've also tried placing the menu call within the <head> tag but it makes no difference.

One thing that may help... is there a way I could capture the output of the menu, and display it later? That is, I suspect the problem is that once even the opening <HTML> tag is sent, it's too late to modify the headers. If I could include the actual HTML for the menus well after I've built them, it might work out better for me.

I tried building the menu before any data is sent, then calling commitMenus(); later on... still no luck, the same error occurs.

Thanks again for your help Andy.

Cheers
Mike

Re: Cannot modify header information - headers already sent


Poster: Andy
Dated: Monday February 8 2010 - 13:40:43 GMT

Ok, I've just installed SMF on our development server here so I can try and reproduce the error.

Which line number in index.template.php are you inserting the menu on (is it 155) and can you please provide the menu code you are using?

If I can reproduce the error I'll be able to fix it or at least find a workaround

Re: Cannot modify header information - headers already sent


Poster: bobbitt
Dated: Monday February 8 2010 - 14:15:55 GMT

Wow, thanks! Here's where I inserted the call... it's close to line 175:

Code:
        // Output any remaining HTML headers. (from mods, maybe?)
        echo $context['html_headers'];

        echo '
</head>
<body>';

// MIKE - Show menu bar
include_once "$include_dir/menu/index.php";

}


I'd be happy to run tests if there's anything I can do to help.

Re: Cannot modify header information - headers already sent


Poster: Andy
Dated: Monday February 8 2010 - 14:28:05 GMT

I see the problem now.

If you use include_once or require_once PHP will execute the specified file before sending any HTML. The script is then attempting to send headers but it cannot because content has already been output to the browser.

It is common sense that it should append the include file at the location specified but PHP will collect all include files and execute them first. What you need to do is put whatever you have being executed in $include_dir/menu/index.php inside a function and execute the function.

If you send over your $include_dir/menu/index.php file I'll see if I can make the changes for you. If you want to email it, please send it to my forum usernameATforum domain name

Cheers,
Andy

Re: Cannot modify header information - headers already sent


Poster: bobbitt
Dated: Tuesday June 8 2010 - 20:30:51 BST

Andy,

Good news... I finally solved this problem. In mm_phpmenu.php, there are 2 flush() commands... they were clearing the output buffer and preventing any further changes to the header. As soon as I commented out those 2 lines, the warning went away. I am now a happy camper.


Cheers
Mike

Re: Cannot modify header information - headers already sent


Poster: Andy
Dated: Monday June 14 2010 - 11:29:14 BST

That should be fine as long as the buffer does not get full - once it does it will automatically flush to the browser.

I still think that you may need to move things about but I suppose that as long as it's working might be an idea to just leave things be.

Re: Cannot modify header information - headers already sent


Poster: bobbitt
Dated: Monday June 14 2010 - 12:22:41 BST

Thanks Andy... I tried for literally hours to juggle things around, and no combo I found would work, so I'm satisfied with this. If the problem starts to recur I can take another look... or just increase the PHP buffer. ;)


Cheers
Mike