andyalean Posted April 27, 2009 Share Posted April 27, 2009 Hello I am starting to use php.I am trying to work with sessions,and have come up with error from a small php file. <?php session_start(); $user = $_SESSION['user']; echo $_SESSION['user']; ?> There are 2 warnings of on Warning: session_start(). Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\xampp\htdocs\Sessions\index.php: in C:\xampp\htdocs\Sessions\index.php on line 10 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\Sessions\index.php: in C:\xampp\htdocs\Sessions\index.php on line 10 How do I enable my php install to use sessions like I have demonstrated? Quote Link to comment https://forums.phpfreaks.com/topic/155769-beginning-sessions-with-problem/ Share on other sites More sharing options...
premiso Posted April 27, 2009 Share Posted April 27, 2009 Read the error. You already have output on line 8 of index.php. You cannot do any type of header function after output has been sent, this includes white spaces, echo's print's etc. Show us the first 15 lines of index.php and we can help you resolve the issue. As the code you have shown here does not correspond with the error you have pasted. EDIT: As a side note, HEADER ERRORS - READ HERE BEFORE POSTING THEM Sticky at the top of this forum. Quote Link to comment https://forums.phpfreaks.com/topic/155769-beginning-sessions-with-problem/#findComment-819956 Share on other sites More sharing options...
andyalean Posted April 27, 2009 Author Share Posted April 27, 2009 Thanks for the quick reply. I modifed the code to just php start my session like so: <?php session_start(); ?> Same as actual layout source code. Then got same error. Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\xampp\htdocs\Sessions\index.php: in C:\xampp\htdocs\Sessions\index.php on line 10 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\Sessions\index.php: in C:\xampp\htdocs\Sessions\index.php on line 10 Wow I got same error? how come this gee what is going wrong um? Quote Link to comment https://forums.phpfreaks.com/topic/155769-beginning-sessions-with-problem/#findComment-819960 Share on other sites More sharing options...
premiso Posted April 27, 2009 Share Posted April 27, 2009 Show us the first 15 lines of index.php and we can help you resolve the issue. As the code you have shown here does not correspond with the error you have pasted. Quote Link to comment https://forums.phpfreaks.com/topic/155769-beginning-sessions-with-problem/#findComment-819961 Share on other sites More sharing options...
andyalean Posted April 27, 2009 Author Share Posted April 27, 2009 Thanks sorry my index.php file is the same as above 3 lines only. like : <?php session_start(); ?> Why do I get this error? Quote Link to comment https://forums.phpfreaks.com/topic/155769-beginning-sessions-with-problem/#findComment-819965 Share on other sites More sharing options...
premiso Posted April 27, 2009 Share Posted April 27, 2009 <?php session_start(); That is considered a whitespace hence output to the browser. <?php echo 'test'; session_start(); That is consider output as well, and will cause the error. <?php session_start(); echo 'test'; That is a valid session_start() given that there is nothing included above etc. You must[/m] have output being started somewhere or else you would not get that error, particularly on line 8 in sessions/index.php as that is what the error states: Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\xampp\htdocs\Sessions\index.php: 8 ) in C:\xampp\htdocs\Sessions\index.php on line 10 Your session_start code is apparently on line 10, given that error message. Quote Link to comment https://forums.phpfreaks.com/topic/155769-beginning-sessions-with-problem/#findComment-819967 Share on other sites More sharing options...
PFMaBiSmAd Posted April 27, 2009 Share Posted April 27, 2009 Based on the line number where the session_start() is and where the error messages states the output is being started at, you have 7 new-lines/lines of html before the <?php tag. Quote Link to comment https://forums.phpfreaks.com/topic/155769-beginning-sessions-with-problem/#findComment-819991 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.