skip to Main Content

I keep getting PHP errors saying PHP Warning: Cannot modify header information – Started at started at /home/www/url.php:2 headers already sent by /home/www/master.php on line 49

In url.php at the top i include master.php once. When i look at Line 49 in master.php see these 2 lines at the bottom of the code.

<?php

    // Application flag
    define('SPF', true);
    
    // absolute document root
    define('DOC_ROOT', realpath(dirname(__FILE__) . '/../'));
    
    // Global include files
    require DOC_ROOT . '/includes/functions.php'; // __autoload() is contained in this file
    require DOC_ROOT . '/includes/class.db.php';
    require DOC_ROOT . '/includes/class.ts.php';
    require DOC_ROOT . '/includes/class.phpmailer.php';
    require DOC_ROOT . '/includes/phpqrcode.php';
    require DOC_ROOT . '/includes/recaptchalib.php';
    
    // Fix magic quotes
    if (get_magic_quotes_gpc())
    {
        $_POST    = fix_slashes($_POST);
        $_GET     = fix_slashes($_GET);
        $_REQUEST = fix_slashes($_REQUEST);
        $_COOKIE  = fix_slashes($_COOKIE);
    }
    
    // Load config settings
    $Config = Config::getConfig();
    
    /* load db config settings into constants */
    $db   = Database::getDatabase();
    $rows = $db->getRows("SELECT config_key, config_value FROM site_config ORDER BY config_group, config_key");
    if (COUNT($rows))
    {
        foreach ($rows AS $row)
        {
            $constantName = "SITE_CONFIG_" . strtoupper($row['config_key']);
            define($constantName, $row['config_value']);
        }
    }
    
    // store session info in the database?
    if ($Config->useDBSessions === true)
    {
        DBSession::register();
    }
    
    // Initialize our session
    session_name($Config->sessionName);
    session_start();

If i move the last 2 lines to the top of the code or above any of the other code the earlier error goes away but instead i see the following new error that i cannot find any solution to.

 PHP Warning:  session_name(): session.name cannot be a numeric or empty '' in /home/www/includes/master.php on line 2: /usr/local/cpanel/cgi-sys/ea-php56, 

It’s the same thing even if i move only session_start(); to the top.

Anyone got any idea on how to solve this ?

2

Answers


  1. Cannot modify header information is caused by you trying to modify headers while you are actually inside the generation of the response body.
    This normally happens when you have any output befoure headers are modified.
    In your case this is caused by the error output before calling session_ functions, stating that session.name cannot be a numeric or empty.
    This error is caused by $Config->sessionName being empty.

    Login or Signup to reply.
  2. 1). Should be no output before "session_start".

    2). "session_name" should be before "session_start"

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search