aminnuto Posted February 18, 2007 Share Posted February 18, 2007 I have an empty php file with this code in it. <?php session_start(); if ($_SESSION['box']) { } else { include('/home/maine/www/inc/box.inc'); $_SESSION['box'] = "value"; } ?> and this page works perfectly. Its supposed to check for the session cookie and if its not set, show this file, but if it is set, dont show the file. BUT, when i insert this code on to the pages through website, they all show this error. Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/main/public_html/page.php: in /home/main/public_html/page.php on line 13 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/main/public_html/page.php.php: in /home/main/public_html/page.php on line 13 None of the other pages set a cookie. So, the code works when its by itself, (on its own blank filename.php page but when I put it on anyother.php file page, i get this error. Anyone know how to get around this? Quote Link to comment Share on other sites More sharing options...
SharkBait Posted February 18, 2007 Share Posted February 18, 2007 I always use this little bit of code when playing with sessions: <?php session_start(); header("Cache-control: private"); // IE6 Fix for Sessions ob_start(); ?> Also when checking a Session I like to use the IsSet() function: <?php if(isset($_SESSION['box'])) { // Session is set } else { // Session is not set } ?> Quote Link to comment Share on other sites More sharing options...
aminnuto Posted February 18, 2007 Author Share Posted February 18, 2007 I'm missing something. <?php if(isset($_SESSION['box'])) { } else { include('/home/main/www/inc/box.inc'); $_SESSION['box'] = "value"; } ?> It shows the box.inc file every time the page is loaded. Quote Link to comment Share on other sites More sharing options...
aminnuto Posted February 18, 2007 Author Share Posted February 18, 2007 correction, this code gives me the same result. works fine when on a page with no other php code. <?php session_start(); header("Cache-control: private"); // IE6 Fix for Sessions ob_start(); ?> <?php if(isset($_SESSION['box'])) { } else { include('/home/main/www/inc/box.inc'); $_SESSION['box'] = "value"; } ?> but when i put it on a page with other php code, it does this. Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/main/public_html/phppage.php: in /home/main/public_html/phppage.php on line 13 Warning: Cannot modify header information - headers already sent by (output started at /home/main/public_html/phppage.php: in /home/main/public_html/phppage.php on line 15 Quote Link to comment Share on other sites More sharing options...
aminnuto Posted February 18, 2007 Author Share Posted February 18, 2007 ok, i figured something out. it has to go before the <html> tag in my .php file. BUT, i need it to go within the body of my page. how do i do that? Quote Link to comment Share on other sites More sharing options...
skali Posted February 18, 2007 Share Posted February 18, 2007 you should use ob_start() function at the top of your page before session_start(); and it should solve your problem. Quote Link to comment Share on other sites More sharing options...
aminnuto Posted February 18, 2007 Author Share Posted February 18, 2007 that solved my problem. thanks 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.