Hangwire Posted September 12, 2010 Share Posted September 12, 2010 Can someone explain to me whats wrong with this? <?php session_start(); // store session data $_SESSION['views']=1; ?> <html> <body> <?php //retrieve session data echo "Pageviews=". $_SESSION['views']; ?> </body> </html> The output it gives me in the browser is this: Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at D:\Program Files\xampp\xampp\htdocs\sessions.php:1) in D:\Program Files\xampp\xampp\htdocs\sessions.php on line 2 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at D:\Program Files\xampp\xampp\htdocs\sessions.php:1) in D:\Program Files\xampp\xampp\htdocs\sessions.php on line 2 Pageviews=1 Explanation? Link to comment https://forums.phpfreaks.com/topic/213249-yet-another-extremely-simple-problem/ Share on other sites More sharing options...
Hypnos Posted September 12, 2010 Share Posted September 12, 2010 You can't output anything before setting headers. session_start() sets headers. Make sure you don't have any spaces before your first <?php. Link to comment https://forums.phpfreaks.com/topic/213249-yet-another-extremely-simple-problem/#findComment-1110366 Share on other sites More sharing options...
Hangwire Posted September 12, 2010 Author Share Posted September 12, 2010 Nope, no spaces. I tried to put it in <head> (I'm not really sure what you mean by setting headers ) but it still gives the same error. Link to comment https://forums.phpfreaks.com/topic/213249-yet-another-extremely-simple-problem/#findComment-1110369 Share on other sites More sharing options...
Ryflex Posted September 12, 2010 Share Posted September 12, 2010 aren't there any enters before <?php make sure the top part of the code is as thight as possible so no enters or spaces or tabs when not needed Link to comment https://forums.phpfreaks.com/topic/213249-yet-another-extremely-simple-problem/#findComment-1110370 Share on other sites More sharing options...
PFMaBiSmAd Posted September 12, 2010 Share Posted September 12, 2010 There's a sticky post for this commonly occurring problem - http://www.phpfreaks.com/forums/index.php/topic,37442.0.html Based on the line number (1) where the output is occurring, you likely have a file saved as a UTF-8 file with the BOM characters. You would need to save the file without the BOM or save it as an ANSI file. Link to comment https://forums.phpfreaks.com/topic/213249-yet-another-extremely-simple-problem/#findComment-1110372 Share on other sites More sharing options...
Hangwire Posted September 12, 2010 Author Share Posted September 12, 2010 Worked like a charm when I converted it to ANSI! Thank you all for the quick replies and patience! Link to comment https://forums.phpfreaks.com/topic/213249-yet-another-extremely-simple-problem/#findComment-1110383 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.