Php session

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lijo
Forum Newbie
Posts: 2
Joined: Tue Apr 27, 2010 2:57 am

Php session

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Php session

Post by requinix »

What's the code?
lijo
Forum Newbie
Posts: 2
Joined: Tue Apr 27, 2010 2:57 am

Re: Php session

Post 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;
        }

    }
}
?>
Last edited by Benjamin on Wed Apr 28, 2010 1:19 am, edited 1 time in total.
Reason: Added [syntax=php] tags.
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

Re: Php session

Post 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.
Post Reply