MAtkins Posted December 14, 2020 Share Posted December 14, 2020 I'm trying to start a session in a simple php file. I keep getting "Cannot send session cache limiter - headers already sent " Here's *all* the code: <?php session_start(); ?> <html> <body> Testing </body> </html> Here's the URL:http://sizzelicks.com/Test2.php Quote Link to comment https://forums.phpfreaks.com/topic/311857-session-start-headers-already-sent-what-am-i-doing-wrong/ Share on other sites More sharing options...
maxxd Posted December 14, 2020 Share Posted December 14, 2020 There's output somewhere before your opening PHP tag. Make sure you don't have a space or carriage return, check other included files, and check your file encoding. Quote Link to comment https://forums.phpfreaks.com/topic/311857-session-start-headers-already-sent-what-am-i-doing-wrong/#findComment-1583050 Share on other sites More sharing options...
MAtkins Posted December 14, 2020 Author Share Posted December 14, 2020 I expected this. Thanks. But, nope. There is no other code, no space before the <?php nothing. What I posted above is exactly what is in the file. I tried attaching the file. They won't let me. You could just copy the code and publish it to your server and see what happens. I'm at a loss. Quote Link to comment https://forums.phpfreaks.com/topic/311857-session-start-headers-already-sent-what-am-i-doing-wrong/#findComment-1583054 Share on other sites More sharing options...
gw1500se Posted December 14, 2020 Share Posted December 14, 2020 (edited) Works for me with Apache. There MUST be some white space or an unprintable code that is being output first. Is this being called from another page or called directly with a URL (that is the way I tested it)? Also, what HTTPD server are you using (Apache, IIS)? Edited December 14, 2020 by gw1500se Quote Link to comment https://forums.phpfreaks.com/topic/311857-session-start-headers-already-sent-what-am-i-doing-wrong/#findComment-1583055 Share on other sites More sharing options...
MAtkins Posted December 14, 2020 Author Share Posted December 14, 2020 I'm on HostGator shared hosting. The code in the file http://sizzelicks.com/Test2.php is *exactly* this (I copy & paste everything): <?php session_start(); ?> <html> <body> Testing </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/311857-session-start-headers-already-sent-what-am-i-doing-wrong/#findComment-1583057 Share on other sites More sharing options...
gw1500se Posted December 14, 2020 Share Posted December 14, 2020 I don't know what they use so you probably need to contact their tech support. As a test, remove the session start then look at the page source to see if there is anything (including white space) before the text. They may be outputting headers or something ahead of your page. Quote Link to comment https://forums.phpfreaks.com/topic/311857-session-start-headers-already-sent-what-am-i-doing-wrong/#findComment-1583060 Share on other sites More sharing options...
requinix Posted December 14, 2020 Share Posted December 14, 2020 Your editor is saving the file with a UTF-8 BOM at the beginning of the file. Tell it not to do that. Quote Link to comment https://forums.phpfreaks.com/topic/311857-session-start-headers-already-sent-what-am-i-doing-wrong/#findComment-1583071 Share on other sites More sharing options...
MAtkins Posted December 15, 2020 Author Share Posted December 15, 2020 (edited) requinix you are correct. I'm using Notepad++ and the file is encoded in utf-8. I have determined that if I encode it in ANSI the problem goes away. If I encode it in utf-8 the problem reoccurs. I've since learned that to check for BOM look in the lower right hand corner of Notepad++. It should say utf-8 BOM. It does NOT say that. It says DOS/Windows utf-8 instead. So, after reading your post I investigated further. I found a setting in Notepad++ that allows me to save in utf-8 without BOM. That solved my problem. THANK YOU!!! Edited December 15, 2020 by MAtkins Quote Link to comment https://forums.phpfreaks.com/topic/311857-session-start-headers-already-sent-what-am-i-doing-wrong/#findComment-1583094 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.