Possible Duplicate:
Headers already sent by PHP
I have php version 5.4.4
I have this code
echo "a";
session_start();
$_SESSION['login'] = "Jhon";
echo $_SESSION['login'];
and this works, why? where is error: "header already sent...." ???
Possible Duplicate:
Headers already sent by PHP
I have php version 5.4.4
I have this code
echo "a";
session_start();
$_SESSION['login'] = "Jhon";
echo $_SESSION['login'];
and this works, why? where is error: "header already sent...." ???
Simply put, output buffering is on, which will make sure your script will work like this. It's not advised to depend on that though, as other servers may not have output buffering on by default. If you wish to turn it off (and I would), change the output_buffering
directive to 0
in your php.ini.
Once the output sent to the browser(even a space),you can not send any header
information to the browser.When you start a new session(using session_start)
a session cookie is sent to the browser from server and this cookie is
basically encapsulated inside the response header.
you can check if headers has already been sent using php function headers_sent()
Though your code worked well with me, but u can try using session_start() before echo statement.