Cannot send session cache limiter

Discuss coding issues, and scripts related to PHP and MySQL.
mlucicom
Posts: 37

Cannot send session cache limiter

I have a php page where i work with session..

Code: Select all

 <?php
  session_start();
if (isset($_SESSION['username'])) {
   $username2=$_SESSION['username'];
   } else {
    echo "<script type='text/javascript'>  window.location='index.php'; </script>";
}
require('layout2.php');

// etc. php code
but i get this error:

Code: Select all

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/mluci/public_html/d/message.php:1) in /home/mluci/public_html/d/message.php on line 1

Admin Posts: 805
Hello,
That error appears because there is something sent to browser before session_start();, like an "echo", or a space or other character before the starting "<?php".
Make sure you put session_start(); before you output any character to browser, not even a space before "<?php".
Also, use a text editor with "Encoding UTF-8 without BOM" (for example Notepad++).

- The same goes for header() and cache() functions.