tags:

views:

48

answers:

4

Salaam Guys,

I don't know why, when I use this method :

session_start();

I see this error , please help me :

session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at D:\Xampp\xampp\htdocs\etest\index.php:1)

My Source :

<?php
ob_start();
session_start();
include("constants.php");
include("includes.php");
?>

<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
<link type="text/css" href="css/main.css" rel="Stylesheet"/>
<script type="text/javascript" src="js/utils.js"></script> 
<title>eTest Examination System</title>
</head>

Thanks for your advice,

Regards,

Mike

A: 

session_start() must be called before any output is sent to the browser.

Incorrect:

<html>
<?php
session_start();

Correct:

<?php
session_start();
?>
<html>
Tim Cooper
Mike Redford
Double check. If there are any spaces before your `<?php` tag, there will be errors.
Tim Cooper
Dear Tom you can see my source code, it's correct.
Mike Redford
@Mike then you may have a BOM issue (see the accepted answer to [this question](http://stackoverflow.com/questions/3557381/warning-cannot-modify-header-information-headers-already-sent)). This answer is correct and does not deserve a downvote.
Pekka
+3  A: 

You should check the invisible characters in source code - especially UTF BOM characted that can mess all the things. What editor are you using?

Tomasz Kowalczyk
the PhpStorm it's a jetbrain's product.
Mike Redford
I haven;t found anything about it but search in menu, saving, editing or so settings and you'll certailny find option to turn it off.
Tomasz Kowalczyk
A: 

Use Notepad++ to switch file encoding to Utf-8 without BOM, or use a HEX editor to see and remove every hidden characters at the beginning of the file. See if that helps.

SinistraD
A: 

I tested this locally and it works fine. Your problem is probably in constants.php or includes.php or something included by one of them. I would try printing ob_get_contents on the first line. If you see whats being printing maybe it'll help find it.

In the past I've used @ob_clean(); because my coworkers had a tendency to leave extra newlines at the end of the files (after the closing ?>). You could also try adding that to your first line.

mqsoh