"Cannot send session cache limiter - headers already sent"

PhpSession

Php Problem Overview


Having a problem with sessions which is becoming very annoying. Every time I try to start a session on a particular page I get the following error:

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at ............ on line 23

using this code:

<?php
session_start();
if(isset($_SESSION['user']))
    {
        $user = $_SESSION['user'];
		echo "$user";
    }
else
    {
    }
?> 

Is it suggesting I've already used session_start(); ? Ive had a look around but nothing really clears this up for me.

Thanks

Php Solutions


Solution 1 - Php

"Headers already sent" means that your PHP script already sent the HTTP headers, and as such it can't make modifications to them now.

Check that you don't send ANY content before calling session_start. Better yet, just make session_start the first thing you do in your PHP file (so put it at the absolute beginning, before all HTML etc).

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser1039878View Question on Stackoverflow
Solution 1 - PhphoubysoftView Answer on Stackoverflow