Jump to content

Session variable problem


fogofogo

Recommended Posts

Hello All,I have a page that passes a session variable to another page which is then used in an if/else statement. For some reason itsa giving me error messages, and I'm not sure whats up with it.Heres the page that creates the variable

<?phpsession_start(); // start session$_SESSION['name'] = 'sport';?>

and heres the page with the if else statment :

<?phpsession_start();$_SESSION['name'];//$name = 'Jester';if ( $name == 'sport' ) { ?><table>stuff in here</table><? } else { ?><table>stuff in here</table><? } ?>
and finally - here are the error messages that I am getting :
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at c:\wamp\www\work\hebbingo\site\test.php:11) in c:\wamp\www\work\hebbingo\site\test.php on line 13Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at c:\wamp\www\work\hebbingo\site\test.php:11) in c:\wamp\www\work\hebbingo\site\test.php on line 13
As you've guessed, I'm pretty new to this so I have probably missed something basic - any ideas?CheersFogo
Link to comment
Share on other sites

The error says you haven't written the session_start() at the VERY beginning of your document. There must be absolutely NO Html before, even no space. So check if it does not begin with <?php, and correct it :)If the opening PHP tag of the section in which the session is started sents HTML, this is also not allowed. session_start should be the very much first command in PHP, that way you can't make any mistake :)Note: you can recognise this very common error by headers already sent by somewhere in the message :(

Link to comment
Share on other sites

The error says you haven't written the session_start() at the VERY beginning of your document. There must be absolutely NO Html before, even no space. So check if it does not begin with <?php, and correct it :)If the opening PHP tag of the section in which the session is started sents HTML, this is also not allowed. session_start should be the very much first command in PHP, that way you can't make any mistake :)Note: you can recognise this very common error by headers already sent by somewhere in the message :(

nice one man - all fixed! :D
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...