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. Link to comment https://forums.phpfreaks.com/topic/118555-problem-with-session_start-function/ 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. Link to comment https://forums.phpfreaks.com/topic/118555-problem-with-session_start-function/#findComment-610358 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. Link to comment https://forums.phpfreaks.com/topic/118555-problem-with-session_start-function/#findComment-610360 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 Link to comment https://forums.phpfreaks.com/topic/118555-problem-with-session_start-function/#findComment-610377 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 Link to comment https://forums.phpfreaks.com/topic/118555-problem-with-session_start-function/#findComment-610379 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; ?> Link to comment https://forums.phpfreaks.com/topic/118555-problem-with-session_start-function/#findComment-610385 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. Link to comment https://forums.phpfreaks.com/topic/118555-problem-with-session_start-function/#findComment-610386 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']; ?> Link to comment https://forums.phpfreaks.com/topic/118555-problem-with-session_start-function/#findComment-610388 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 Link to comment https://forums.phpfreaks.com/topic/118555-problem-with-session_start-function/#findComment-610391 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. Link to comment https://forums.phpfreaks.com/topic/118555-problem-with-session_start-function/#findComment-610392 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. Link to comment https://forums.phpfreaks.com/topic/118555-problem-with-session_start-function/#findComment-610393 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 Link to comment https://forums.phpfreaks.com/topic/118555-problem-with-session_start-function/#findComment-610399 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 Link to comment https://forums.phpfreaks.com/topic/118555-problem-with-session_start-function/#findComment-610406 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.