We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21112
    • 156 Posts
    I am building a MODx site for a client and have been working on it for several weeks. I’m doing only content entry at the moment, so I’ve made no changes to any of the workings of the site. Yet over night something seems to have happened and the site will now not display. The site was working last night, but today I am seeing this error:

    Warning: Cannot modify header information - headers already sent by (output started at /mounted-storage/home43a/sub006/sc32167-DHIS/www/index.php:4) in /mounted-storage/home43a/sub006/sc32167-DHIS/www/index.php on line 1200
    
    Warning: Cannot modify header information - headers already sent by (output started at /mounted-storage/home43a/sub006/sc32167-DHIS/www/index.php:4) in /mounted-storage/home43a/sub006/sc32167-DHIS/www/index.php on line 1201
    
    Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /mounted-storage/home43a/sub006/sc32167-DHIS/www/index.php:4) in /mounted-storage/home43a/sub006/sc32167-DHIS/www/manager/includes/config.inc.php on line 59
    
    Warning: Cannot modify header information - headers already sent by (output started at /mounted-storage/home43a/sub006/sc32167-DHIS/www/index.php:4) in /mounted-storage/home43a/sub006/sc32167-DHIS/www/manager/includes/config.inc.php on line 73
    « MODx Parse Error »
    MODx encountered the following error while attempting to parse the requested resource:
    « PHP Parse Error »
     
    PHP error debug
      Error: 	Cannot modify header information - headers already sent by (output started at /mounted-storage/home43a/sub006/sc32167-DHIS/www/index.php:4)	 
      Error type/ Nr.: 	Warning - 2	 
      File: 	/mounted-storage/home43a/sub006/sc32167-DHIS/www/manager/includes/document.parser.class.inc.php	 
      Line: 	466	 
      Line 466 source: 	header('Content-Type: ' . $type . '; charset=' . $this->config['modx_charset']); 	 
     
    Parser timing
      MySQL: 	0.0095 s	(9 Requests)
      PHP: 	0.7636 s	 
      Total: 	0.7730 s



    The manager works just fine, and no other mysql apps (eg forum) on the server are giving me problems. Any idea what could be causing this?

    Some details:
    Site url: http://www.vicphysics.org/
    Modx version: 0.9.6
    Phpinfo: http://www.vicphysics.org/phpinfo.php


    Any help you can offer would be appreciated.
      • 22303 MODX Staff
      • 10,725 Posts
      Not having any problem here. Was the problem temporary?
        • 21112
        • 156 Posts
        Ah crap, sorry. I gave the url for the old site which is running in parallel with the in development site. The problem url us: http://www.vicphysics.org/index.php
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          config.inc.php is throwing some kind of error, it looks like. By itself it doesn’t send anything to the screen, so it must be an error message being generated.
            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
            • 21112
            • 156 Posts
            Hmm I haven’t made any changes to my config, but in the past with other web hosts, I’t not been unheard of for the host to make changes without telling me because there was too much load being generated by the script or some such nonsense.

            Here’s my current config file (with the password obscured). Does this tell you anything?

            <?php
            /**
             *	MODx Configuration file
             */
            $database_type = 'mysql';
            $database_server = 'mysql1037.servage.net';
            $database_user = 'vicmodx';
            $database_password = '**********';
            $database_connection_charset = '';
            $dbase = '`vicmodx`';
            $table_prefix = 'modx_';		
            error_reporting(E_ALL & ~E_NOTICE);
            
            $lastInstallTime = 1187771065;
            
            $site_sessionname = 'SN46cbf2b835535';
            $https_port = '443';
            
            // automatically assign base_path and base_url
            if(empty($base_path)||empty($base_url)||$_REQUEST['base_path']||$_REQUEST['base_url']) {
                $sapi= 'undefined';
                if (!strstr($_SERVER['PHP_SELF'], $_SERVER['SCRIPT_NAME']) && ($sapi= @ php_sapi_name()) == 'cgi') {
                    $script_name= $_SERVER['PHP_SELF'];
                } else {
                    $script_name= $_SERVER['SCRIPT_NAME'];
                }
                $a= explode("/manager", str_replace("\\", "/", dirname($script_name)));
                if (count($a) > 1)
                    array_pop($a);
                $url= implode("manager", $a);
                reset($a);
                $a= explode("manager", str_replace("\\", "/", dirname(__FILE__)));
                if (count($a) > 1)
                    array_pop($a);
                $pth= implode("manager", $a);
                unset ($a);
                $base_url= $url . (substr($url, -1) != "/" ? "/" : "");
                $base_path= $pth . (substr($pth, -1) != "/" && substr($pth, -1) != "\\" ? "/" : "");
                // assign site_url 
                $site_url= ((isset ($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') || $_SERVER['SERVER_PORT'] == $https_port) ? 'https://' : 'http://';
                $site_url .= $_SERVER['HTTP_HOST'];
                if ($_SERVER['SERVER_PORT'] != 80)
                    $site_url= str_replace(':' . $_SERVER['SERVER_PORT'], '', $site_url); // remove port from HTTP_HOST Â 
                $site_url .= ($_SERVER['SERVER_PORT'] == 80 || (isset ($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') || $_SERVER['SERVER_PORT'] == $https_port) ? '' : ':' . $_SERVER['SERVER_PORT'];
                $site_url .= $base_url;
            }
            
            if (!defined('MODX_BASE_PATH')) define('MODX_BASE_PATH', $base_path);
            if (!defined('MODX_BASE_URL')) define('MODX_BASE_URL', $base_url);
            if (!defined('MODX_SITE_URL')) define('MODX_SITE_URL', $site_url);
            if (!defined('MODX_MANAGER_PATH')) define('MODX_MANAGER_PATH', $base_path.'manager/');
            if (!defined('MODX_MANAGER_URL')) define('MODX_MANAGER_URL', $site_url.'manager/');
            
            // start cms session
            if(!function_exists('startCMSSession')) {
            	function startCMSSession(){
            		global $site_sessionname;
            		session_name($site_sessionname);	
            		session_start();
            		$cookieExpiration= 0;
                    if (isset ($_SESSION['mgrValidated']) || isset ($_SESSION['webValidated'])) {
                        $contextKey= isset ($_SESSION['mgrValidated']) ? 'mgr' : 'web';
                        if (isset ($_SESSION['modx.' . $contextKey . '.session.cookie.lifetime']) && is_numeric($_SESSION['modx.' . $contextKey . '.session.cookie.lifetime'])) {
                            $cookieLifetime= intval($_SESSION['modx.' . $contextKey . '.session.cookie.lifetime']);
                        }
                        if ($cookieLifetime) {
                            $cookieExpiration= time() + $cookieLifetime;
                        }
            			if (!isset($_SESSION['modx.session.created.time'])) {
            			  $_SESSION['modx.session.created.time'] = time();
            			}														
                    }
            		setcookie(session_name(), session_id(), $cookieExpiration, MODX_BASE_URL);
            	}
            }
            ?>


            I’ve double checked and the database settings are all correct, including the server address.
              • 3749
              • 24,544 Posts
              I think the most common cause of that error is having stuff in a .php file that comes before or after the opening and closing php tags. Sometimes, a single space character after the closing tag can do it. One fix is to omit the closing php tag altogether.

              Some text editors insert an EOL or EOF character at the end of the file so if you edited either index.php or config.inc.php, that could be it.

              .php files that are included are also suspect as is header-generating content (e.g. session_start() ) that comes after any HTML output (which includes blank lines).


              Bob
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 21112
                • 156 Posts
                THANK YOU for the tip BobRay. I was confused since I haven’t touched any of those files in ages, but I checked them anyway. It turns out the site had somehow been hacked. The index.php file contained thousands of links to viagra sales sites added to the top of the file. I have no idea how this could have happened, and I’ll be speaking to my web host to try and get to the bottom of this. After removing the offending lines, the site worked fine again.
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  You can set your config.inc.php file and the index.php files in root and /manager to read-only. These seem to be the files most commonly attacked.
                    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
                    • 21112
                    • 156 Posts
                    They’re currently (and have been since after installation) set to chmod 644, which if I’m correct means they can only be changed by the owner, right? So only someone who has logged in to the server with the correct username and password will be able to make any edits. Am I right?

                    I will change the passwords just to be sure.
                      • 28042 ☆ A M B ☆
                      • 24,524 Posts
                      Also anyone who gains "root" access to your server can change them. This is most likely what happened. Of course, if that is the case they could change the permissions on your files as well, but at least it’s a small deterrent to casual drive-by change attempts.
                        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