doforumda Posted August 7, 2008 Share Posted August 7, 2008 hello there, i am experiencing a problem in my php script. The problem is with session_start() function. when i write this function in my script and run the script in my browser the following error displays "Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at f:\wamp\www\examples\show_session_var.php:9) in f:\wamp\www\examples\show_session_var.php on line 10" "Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at f:\wamp\www\examples\show_session_var.php:9) in f:\wamp\www\examples\show_session_var.php on line 10" above both errors are the same but my browser display it two times. Do anyone know whats the problem pleasee help if anybody knows. thanks. Quote Link to comment Share on other sites More sharing options...
peranha Posted August 7, 2008 Share Posted August 7, 2008 session_start(); has to be at the very top of the page. Quote Link to comment Share on other sites More sharing options...
trq Posted August 7, 2008 Share Posted August 7, 2008 session_start(); has to be at the very top of the page. Not exactly true, it does however need to go before any output is sent to the browser. Quote Link to comment Share on other sites More sharing options...
doforumda Posted August 7, 2008 Author Share Posted August 7, 2008 session_start(); has to be at the very top of the page. yes i typed it at the top but still the same problem Quote Link to comment Share on other sites More sharing options...
peranha Posted August 7, 2008 Share Posted August 7, 2008 Can you post what you currently have for this file show_session_var.php Quote Link to comment Share on other sites More sharing options...
doforumda Posted August 7, 2008 Author Share Posted August 7, 2008 Can you post what you currently have for this file show_session_var.php yes sure this is the first page "sessions.php" <?php session_start(); $color = "blue"; session_register("color"); echo "<a href = 'show_session_var.php'>Click Here</a>"; ?> this is the second "show_session_var.php" <?php session_start(); echo "My favourite color is .....".$color; ?> Quote Link to comment Share on other sites More sharing options...
peranha Posted August 7, 2008 Share Posted August 7, 2008 The error is occurring in show_session_var.php on line 9. You only showed 2 lines in that file. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted August 7, 2008 Share Posted August 7, 2008 The error message mentions line 9 of show_session_var.php, yet you showed us only 2 lines, where are the rest? Those scripts are written with the assumption that register_globals is enabled. This hasn't been the case in many years. Also, session_register() is depreciated and shouldn't be used. Try this: sessions.php <?php session_start(); $_SESSION['color'] = "blue"; echo "<a href = 'show_session_var.php'>Click Here</a>"; ?> show_session_var.php <?php session_start(); echo "My favourite color is .....".$_SESSION['color']; ?> Quote Link to comment Share on other sites More sharing options...
doforumda Posted August 7, 2008 Author Share Posted August 7, 2008 The error is occurring in show_session_var.php on line 9. You only showed 2 lines in that file. yes its actually like this <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Untitled Document</title> </head> <body> <?php session_start(); echo "My favourite color is .....".$color; ?> </body> </html> i just didnt mention the html code Quote Link to comment Share on other sites More sharing options...
trq Posted August 7, 2008 Share Posted August 7, 2008 Did you not read the reply where I said session_start() must come before any output is sent to the browser? Html is output. Quote Link to comment Share on other sites More sharing options...
peranha Posted August 7, 2008 Share Posted August 7, 2008 that is why it is erroring out is because of the HTML. Quote Link to comment Share on other sites More sharing options...
doforumda Posted August 7, 2008 Author Share Posted August 7, 2008 that is why it is erroring out is because of the HTML. thank you peranha its working thanks for helping Quote Link to comment Share on other sites More sharing options...
doforumda Posted August 7, 2008 Author Share Posted August 7, 2008 Did you not read the reply where I said session_start() must come before any output is sent to the browser? Html is output. yes i read that i thought the top means "at the top in php script" thanks for helping Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.