Rheves Posted August 10, 2010 Share Posted August 10, 2010 I have several pages on my site using the exact same code at the very top, which works fine except for one page: <?php include_once("../members/dbinfo.php"); The top of dbinfo looks like this: <?php session_start(); And then the connection strings for the database However it is giving me this error on this one page: Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\Inetpub\WebSites\premierathome_com\products\FrenchTalkingDictionary.php:1) in C:\Inetpub\WebSites\premierathome_com\members\dbinfo.php on line 1 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\Inetpub\WebSites\premierathome_com\products\FrenchTalkingDictionary.php:1) in C:\Inetpub\WebSites\premierathome_com\members\dbinfo.php on line 1 Now the session does actually start and doesn't prevent anything from working, I just get those messages. I'm at a loss as to why a different page with the exact same code, save for searching the database for a different product version would have this problem. I have had this code in place as well which works fine on other pages but doesn't help my problem at all: if(!isset($_SESSION['OK'])){ session_start(); } OK being a variable I set up during log in. I'm at a loss, is anyone able to help me out with this? Quote Link to comment Share on other sites More sharing options...
meltingpoint Posted August 10, 2010 Share Posted August 10, 2010 session_start() should only be at the top of the one page- the page that you are calling the include into. <?php session_start(); blahblahblah- code here include("../members/dbinfo.php"); blahblahblah- more code here ?> If you were to have session_start(); at the beginning of the page that you include- you would then be calling session_start() twice in one page. Hope that helps. Quote Link to comment Share on other sites More sharing options...
Rheves Posted August 10, 2010 Author Share Posted August 10, 2010 I changed the code to <?php //include_once("../members/dbinfo.php"); session_start(); //DBINFO HERE And now the error reads: Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\Inetpub\WebSites\premierathome_com\products\FrenchTalkingDictionary.php:1) in C:\Inetpub\WebSites\premierathome_com\products\FrenchTalkingDictionary.php on line 3 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\Inetpub\WebSites\premierathome_com\products\FrenchTalkingDictionary.php:1) in C:\Inetpub\WebSites\premierathome_com\products\FrenchTalkingDictionary.php on line 3 I had included the session start call on that page because every page on the site needed it and the db connection string. Quote Link to comment Share on other sites More sharing options...
meltingpoint Posted August 10, 2010 Share Posted August 10, 2010 Then..............put session_start() at the beginning of the page that is calling include and not in the included file. Also..........session_start() must be the first thing at the top of the page. No other output such as html, error messages or anything else can precede it like <head>, or <title> etc.... With out seeing the entire page that you say you have started the session_start() on - it is not possible for us to trouble shoot. Same with the dbinfo.pphp. Quote Link to comment Share on other sites More sharing options...
onlyican Posted August 10, 2010 Share Posted August 10, 2010 The way I work is I have a global constants file which is called at the top of EVERY page This contains my php settings such as session_start(); Even shows before I debug my code (echo out above header) Quote Link to comment Share on other sites More sharing options...
Adam Posted August 10, 2010 Share Posted August 10, 2010 As meltingpoint said, you cannot have any output before the session_start() call, even white-space. I'd check the problematic file for a line break or single space that could be triggering the error. Though I disagree about your other point meltingpoint, placing the session_start() call within the included file is the best idea. Since you're going to be using it on virtually every page it makes sense not to repeat it every time. Quote Link to comment Share on other sites More sharing options...
meltingpoint Posted August 10, 2010 Share Posted August 10, 2010 Mr. Adam- Consider a code where session_start() is at the begining of a page and then runs some code that produces some out put and continues along and also then includes() a file that has session_start() in it also. Won't that generate an error as technically- there was output to the browser or white space etc... Quote Link to comment Share on other sites More sharing options...
Adam Posted August 10, 2010 Share Posted August 10, 2010 If you have session_start() within a file that you include on every page, why would you use it again? Quote Link to comment Share on other sites More sharing options...
Rheves Posted August 10, 2010 Author Share Posted August 10, 2010 I've eliminated the included dbinfo.php for troubleshooting, it only had the db variables and session start call anyway. Here's my page up until the html begins: <?php session_start(); //DB Info $LoggedIn = "No"; if(isset($_SESSION['OK'])){ $LoggedIn = "Yes"; } //Mysql Queries ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> session_start() Is the first thing that happens, no output before it. I've made sure there's no spaces before it. The only other php code on the page is displaying the information gathered from the mysql queries. Quote Link to comment Share on other sites More sharing options...
onlyican Posted August 10, 2010 Share Posted August 10, 2010 And what error are you getting now? Quote Link to comment Share on other sites More sharing options...
Rheves Posted August 10, 2010 Author Share Posted August 10, 2010 Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\Inetpub\WebSites\premierathome_com\products\FrenchTalkingDictionary.php:1) in C:\Inetpub\WebSites\premierathome_com\products\FrenchTalkingDictionary.php on line 2 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\Inetpub\WebSites\premierathome_com\products\FrenchTalkingDictionary.php:1) in C:\Inetpub\WebSites\premierathome_com\products\FrenchTalkingDictionary.php on line 2 Quote Link to comment Share on other sites More sharing options...
Adam Posted August 10, 2010 Share Posted August 10, 2010 Are you using a free host site, that are inserting adverts? If not, what does C:\Inetpub\WebSites\premierathome_com\products\FrenchTalkingDictionary.php have to do with things? Quote Link to comment Share on other sites More sharing options...
Rheves Posted August 10, 2010 Author Share Posted August 10, 2010 We are not using a free host or have any content being inserted, that's just the file path on their server to our page I take it. FrenchTalkingDictionary.php is the problematic page. Quote Link to comment Share on other sites More sharing options...
onlyican Posted August 10, 2010 Share Posted August 10, 2010 Do you have a link???? Quote Link to comment Share on other sites More sharing options...
Adam Posted August 10, 2010 Share Posted August 10, 2010 Okay. Well somehow there is output before that session_start() call. Try viewing the source, anything there before the doctype? Quote Link to comment Share on other sites More sharing options...
Rheves Posted August 10, 2010 Author Share Posted August 10, 2010 This is what I get looking at the source code: <br /> <b>Warning</b>: session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cookie - headers already sent by (output started at C:\Inetpub\WebSites\premierathome_com\products\FrenchTalkingDictionary.php:1) in <b>C:\Inetpub\WebSites\premierathome_com\products\FrenchTalkingDictionary.php</b> on line <b>2</b><br /> <br /> <b>Warning</b>: session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent (output started at C:\Inetpub\WebSites\premierathome_com\products\FrenchTalkingDictionary.php:1) in <b>C:\Inetpub\WebSites\premierathome_com\products\FrenchTalkingDictionary.php</b> on line <b>2</b><br /> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> Quote Link to comment Share on other sites More sharing options...
meltingpoint Posted August 10, 2010 Share Posted August 10, 2010 Mr. Adam I agree. My point is that if he includes a global file that has session_start() at the top of every page, or if he simply puts session_start() at the top of each page.............then in any include() file that he adds to that page........he would not put session_start() at the top of that included page. Using his included file- dbinfo.php as an example which he stated he use session_start() again. Quote Link to comment Share on other sites More sharing options...
Rheves Posted August 10, 2010 Author Share Posted August 10, 2010 I never had two session start calls, sorry if I implied that somewhere. I was originally calling the session start within dbinfo.php and not on the calling page, but changed that during troubleshooting to remove dbinfo.php and call session start on the problematic page. Quote Link to comment Share on other sites More sharing options...
onlyican Posted August 10, 2010 Share Posted August 10, 2010 Most Common Issue I have seen is a space before the <?php tag <?php //Code here [code] Quote Link to comment Share on other sites More sharing options...
Adam Posted August 10, 2010 Share Posted August 10, 2010 I changed the code to <?php //include_once("../members/dbinfo.php"); session_start(); //DBINFO HERE Rheves only added session_start() within the file in an effort to debug the code; he commented out the dbinfo.php file. Okay, the error says there is a problem on line 1 of FrenchTalkingDictionary.php, what is line 1? Quote Link to comment Share on other sites More sharing options...
Rheves Posted August 10, 2010 Author Share Posted August 10, 2010 Line 1 is now <?php session_start(); I tried that to avoid any possible whitespace between line 1 and 2. E: Also I have checked for a space behind <php, there is nothing there. Quote Link to comment Share on other sites More sharing options...
onlyican Posted August 10, 2010 Share Posted August 10, 2010 it should but amuse me here. Line 9 is giving an error as well for undefined UserID Comment this line out. (Yes I found the site, it aint that difficult) Quote Link to comment Share on other sites More sharing options...
Rheves Posted August 10, 2010 Author Share Posted August 10, 2010 Yeah, once I realized the error that was spit out gave the url it was too late to modify the post. That's not encountered if you're logged in, a bit of laziness on my part.. no one should be seeing that. Quote Link to comment Share on other sites More sharing options...
onlyican Posted August 10, 2010 Share Posted August 10, 2010 Also Standards of Websites <html> <head> //Title Meta ect </head> <body> The website Stuff </body> </html> You have in your code Half way through the Body <HTML> <!-- @page { margin: 0.79in } P { margin-bottom: 0.08in } --> <BODY DIR="LTR"> </p> Quote Link to comment Share on other sites More sharing options...
onlyican Posted August 10, 2010 Share Posted August 10, 2010 Its not too late to modify, I wont tell anyone Please at least wrap it in isset() to humor me 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.