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.
Php session
Moderator: General Moderators
Re: Php session
What's the code?
Re: Php session
For the session related function I am using one class and including it in the index.php
This is my 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.
Reason: Added [syntax=php] tags.
Re: Php session
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.