Page 1 of 1

Php session

Posted: Tue Apr 27, 2010 3:16 am
by lijo
I am getting the following error on all the rendered pages on my localhost:
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /..../php/index.php:19) in /...../session.php on line 5

I have exactly the same code on my server and it works fine there.

On my local host I have LinuxMint installed and CentOS on my server.
I am defining the session functions from a common session.php file and calling it in the index.php by creating its objects.
I have searched about this issue in multiple forums online, and standard solution seems to be to remove the white spaces, which is not an issue here.

Have any of you faced a similar issue and how did you resolve it?

Thank You.

Re: Php session

Posted: Tue Apr 27, 2010 4:12 am
by requinix
What's the code?

Re: Php session

Posted: Wed Apr 28, 2010 12:28 am
by lijo
For the session related function I am using one class and including it in the index.php

This is my index.php

Code: Select all

<?php
require_once('../session.php');
$session = new session();
If($session->issession()) { // go ahead } else { redirect(/login');} 
?>
<!DOCTYPE html  ...
<html>
</html>


session.php

<?php
class session {
    function start() {
        if(!session_id()) {
            session_start();
        }
    }
    
    function issession() {
        $this->start();// Initialize the session.
         if(!session_id())
            return FALSE;
        } else {
            return TRUE;
        }

    }
}
?>

Re: Php session

Posted: Wed Apr 28, 2010 3:06 am
by Apollo
You have whitespaces, newlines, or UTF-8 markers at the beginning of index.php or session.php (or both). Check both files, in a hex editor if you need to, look for any bytes before the <?php open tag.