Page 1 of 1
Cannot send session cookie - headers alread
Posted: Wed Apr 21, 2010 12:23 am
by thamizh
warning : session_start() [function.session-start]: Cannot send session cookie - headers already sent by
After googling i found that i should remove any white spaces before the session_start()
i did that too
but am getting above mentioned warning
y i dont know

anyone pls help me
Re: Cannot send session cookie - headers alread
Posted: Wed Apr 21, 2010 12:41 am
by requinix
What's the code? Start at the very beginning of the file and go up to whatever line the error message says.
Re: Cannot send session cookie - headers alread
Posted: Wed Apr 21, 2010 12:52 am
by thamizh
<?php
session_start();
$dbHost = 'localhost';
this is first two lines of the code
Re: Cannot send session cookie - headers alread
Posted: Wed Apr 21, 2010 1:17 am
by requinix
And there is absolutely nothing before the "<?php"?
What are you using to write code?
Re: Cannot send session cookie - headers alread
Posted: Wed Apr 21, 2010 2:28 am
by thamizh
got the result

There is a whitespace before the <?php
so the warning comes
sortted out

thanks for your help tasairis

Re: Cannot send session cookie - headers alread
Posted: Wed Apr 21, 2010 2:29 am
by Apollo
tasairis wrote:And there is absolutely nothing before the "<?php"?
That includes an invisible UTF-8 byte order mark. Can you open the file in a hex-editor?
And is this the file you're calling directly, or is it included from somewhere else?
(edit) oh, solved, nevermind

Re: Cannot send session cookie - headers alread
Posted: Wed Apr 21, 2010 2:37 am
by cerberusstudios
In PHP 5 you can no longer start your HTML before your session. so even if session_start(); is your first line of code for PHP if you have html before it you will get that error. Even the doctype cannot come before the session (someone please correct me if i am wrong on that, but I am fairly certain). The code you are looking for is similar to the following:
Code: Select all
<?php
session_start();
?>
<html>
</html>
Re: Cannot send session cookie - headers alread
Posted: Fri Apr 23, 2010 6:12 am
by Apollo
cerberusstudios wrote:In PHP 5 you can no longer start your HTML before your session.
This has nothing to do with PHP version 5 (or PHP whatsoever).
Sessions = involves cookie, and cookies are HTTP header.
HTML = content that's being sent after the header, by definition.
So once you started generating any actual output, you can no longer send or modify any headers.
Even the doctype cannot come before the session (someone please correct me if i am wrong on that, but I am fairly certain).
doctype = html = part of regular output / content (i.e. can never precede headers)