Thread tagged as: Question, Problem

Headers ready sent warning

Hi Drew,

I'm getting the following error message having moved my development site to the live server. Everything worked fine on the development server - no errors.

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /data02/c6524905/public_html/admin/templates/pages/home.php:3) in /data02/c6524905/public_html/admin/templates/layouts/global.header.php on line 2

Its a multi lingual site and the tmeplate starts thus

<?php include('admin/runtime.php'); ?>

    $lang = PerchSystem::get_var('lang');

and the contents of global.header are…

// Set the lang variable to our default
$lang = 'en'; 
// Get the lang query string from the URL
switch(perch_get('lang')) {
    // set the lang variable according to the query string
    case 'en':
        $lang = 'en';
    case 'fr':
        $lang = 'fr';
    // if there is no query string, check for a session cookie
        if (isset($_SESSION['lang'])) {
            $lang = $_SESSION['lang'];
// set our session cookie to whatever the lang variable is
$_SESSION['lang'] = $lang;
// make the $lang variable available in HTML templates
PerchSystem::set_var('lang', $lang);

<!doctype html>
<html class="no-js" lang="<?php echo $lang;?>">
    <meta charset="utf-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge">

<?php if($lang == 'fr'){ ?>
 <title><?php perch_page_attribute('pageTitle-fr') ?></title>
<?php } else { ?>
 <title><?php perch_pages_title(); ?></title>
<?php } ?>

    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <link rel="apple-touch-icon" href="apple-touch-icon.png">
    <!-- Place favicon.ico in the root directory -->

    <!-- Webfont links-->
    <link rel="stylesheet" type="text/css" href="" />

    <link rel="stylesheet" href="/css/normalize.css">
    <link rel="stylesheet" href="/css/main.css">
    <link rel="stylesheet" href="/css/navigation.css">

    <script src="js/vendor/modernizr-2.8.3.min.js"></script>

The only thing called before this is the admin/runtime.php as always your help would be much appreciated.

Nick Loat

Nick Loat 0 points

  • 5 years ago
Rachel Andrew

Rachel Andrew 394 points
Perch Support

I imagine the issue is the whitespace in your file. If you output anything including white space before sending headers you are going to get an error.

Yep. Your bang on! Just found out about it and it fixed the issue - very annoying. Thanks Rachel.