We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6948
    • 12 Posts
    Hi we’re getting this error every time we load up a page on the first try:

    Cannot modify header information - headers already sent by (output started at /home/www/vhosts/everynation.org/httpdocs/manager/includes/document.parser.class.inc.php:452)

    We’re using the FirstChildRedirect snippet that checks if someone’s already logged in through the manager as well as QuickEdit.

    I’m suspecting it might be something to do with the sequence that ModX spits out header() tags.. but I can’t quite point it out which area in the code this happens.

    Please check: www.wineverynation.org

    Anyone else have a similar situation?

    Thanks!
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      I don’t see anything wrong ?
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 6948
        • 12 Posts
        try this site:

        http://www.everynationpv.org

        or

        http://websites.wineverynation.org/encv.html

        These are sites that are both installed within the same ModX installation.

        Scoll down to the footer of the page, you’ll see it.


          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Ok, I see.

          Try the page plain, without the extra features, then add them one by one to see which one breaks it.

          Hm...I set up my dev site with a folder with children, put the FirstChildRedirect snippet as its only content, and made sure QuickEdit was enabled. I cannot reproduce the problem. Will try on my remote site.

          Works fine on my remote site as well.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 6948
            • 12 Posts
            thanks, yea I suspect it may be FirstChildRedirect. seems to work fine without it although since I’m not the only one working on this the other developers across the ocean might need it so I don’t want to get rid of it for now.

            Can you send over your version of FirstChildRedirect, I notice ours has some peculiarities: Here’s the code:

            // HACK
            // If you’re logged in as a manager, don’t redirect but
            // instead show an instructions page on how to use MODx to
            // modify their site. Also explain the template variablge
            // change concept.

            // Note: can’t use getLoginUserType because you have to be in the
            // backend for that function to work.

            // Further hack: only show this if you have the church admin role

            $InstructionsChunkName = "ENAdminHelp";
            $ChurchAdminRoleID = 2;
            $DoRedirect = true;

            if (isset($_SESSION[’mgrValidated’])) {
            $info = $getUserInfo[$_SESSION[’mgrInternalKey’]];
            $DoRedirect = !($info["role"] == $ChurchAdminRoleID);
            }

            if ($DoRedirect) {
            if (!isset($id)) $id=$modx->documentIdentifier;
            $children=$modx->getActiveChildren($id,’menuindex’,’ASC’);
            $firstChildUrl = 0;
            if (!$children===false) {
            $firstChild = $children[0];
            $firstChildUrl = $modx->makeUrl($firstChild[’id’]);
            }
            if ($firstChildUrl) {
            // Danny:
            // testing if this makes a difference to the headers() already sent out error we get at each page footer
            //return $modx->sendRedirect($firstChildUrl,0,’REDIRECT_META’);
            // nope, it doesn’t! seems to happen after the redirect tongue below is the original code
            return $modx->sendRedirect($firstChildUrl);
            } else {
            return "<p>There are currently no pages here. Please check back later.</p>";
            }
            } else {
            // display the instructions chunk
            return $modx->getChunk($InstructionsChunkName);
            }
              • 6948
              • 12 Posts
              I think I got it but I duno if this is the cleanest way to solve this. I ended up tweaking manager/includes/document.parser.class.inc.php itself.

              The problem is still probably is with our version of FirstChildRedirect and QuickEdit combined or so but I can’t seem to pinpoint where its trying to send extra headers that have already been sent out...

              Anyways, here’s my code I added in line 416 of document.parser.class.inc.php where it basically has this one single `header($header);` line:

              // Danny van Ommen: February 22, 2006
              // original code is just:
              // header($header);
              // modified with an if(!headers_sent())
              // this if() statement addresses the error that comes up at the footer:
              /* Warning: Cannot modify header information - headers already sent by
              (output started at /home/www/vhosts/everynation.org/httpdocs/manager/includes/
              document.parser.class.inc.php:472) in
              /home/www/vhosts/everynation.org/httpdocs/manager/includes/document.parser.class.inc.php
              on line 416 : header($header)
              */
              if(!headers_sent()){
              header($header);
              }
              else{
              // this addresses the 2nd error that comes up at the footer
              // duno if plain old exit; is the best solution but it seems to work!
              /*
              MODx encountered the following error while attempting to parse the requested resource:
              « Execution of a query to the database failed - Duplicate entry ’2147483647’ for key 1 »
              SQL: INSERT INTO `enDB`.modx_log_user_agents(id, data) VALUES(’3767326138’, ’Firefox/1.5.0.1’)
              */
              exit;
              }
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                The version I have is exactly the same as the basic part of yours, I think:

                if (!isset($id)) $id=$modx->documentIdentifier;
                $children=$modx->getActiveChildren($id,'menuindex','ASC');
                $firstChildUrl = 0;
                if (!$children===false) {
                  $firstChild = $children[0];
                  $firstChildUrl = $modx->makeUrl($firstChild['id']);
                }
                if ($firstChildUrl) {
                return $modx->sendRedirect($firstChildUrl);
                } else {
                  return "<p>There are currently no pages here. Please check back later.</p>";
                }

                  Studying MODX in the desert - http://sottwell.com
                  Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                  Join the Slack Community - http://modx.org
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  This line

                    $info = $getUserInfo[$_SESSION['mgrInternalKey']];


                  needs to be

                   $info = $modx->getUserInfo($_SESSION['mgrInternalKey']);
                    Studying MODX in the desert - http://sottwell.com
                    Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                    Join the Slack Community - http://modx.org
                    • 7923
                    • 4,213 Posts
                    Hi,

                    I got this exactly same problem with my modx 0.9.1 and I know that it’s not about the snippets, because I have the same problem also when using Etomite. I don’t know what is actually sending out the headers twice, but I know it has probably something to do with the visitor logging code. If I set the visitor logging to be off from the manager, there aren’t any parse errors visible at front end. But if the visitor logging is on, there will be this error at the page footer at the first page load:

                    Error: Cannot modify header information - headers already sent
                    Error type/ Nr.: Warning - 2
                    File: /www/03/net/modx/manager/includes/document.parser.class.inc.php
                    Line: 416
                    Line 416 source: header($header);

                    So there’s some bug somewhere that affects only certain server enviroments. I have couple sites on the same host and all of them are having this problem. In other enviroments, I have no problem. I’ve also seen many others having the same issue at Etomite forums.

                    My enviroment:

                    MODx: 0.9.1 Out-of-the-Box, only installed
                    OS: Debian 3.1, Linux 2.6 (x86_64)
                    WWW: Apache 1.3
                    PHP: PHP 4.4.1 (+gd 2.0, curl, ctype, libxml)
                    SQL: MySQL 4.1.11


                      "He can have a lollipop any time he wants to. That's what it means to be a programmer."
                      • 28042 ☆ A M B ☆
                      • 24,524 Posts
                      I have almost always found these errors to result from php itself, outside of MODx, trying to set an error message at some point after headers have already been established by the code of MODx.
                        Studying MODX in the desert - http://sottwell.com
                        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                        Join the Slack Community - http://modx.org