mrras25 Posted June 27, 2008 Share Posted June 27, 2008 I am getting the following errors when trying to unset cookies: Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\staging\includes\functions.php:209) in C:\wamp\www\staging\logout.php on line 19 The code is as follows: logout.php: <? session_start(); require('includes/functions.php'); $pgval = (is_logged_in($user) ? 0 : 1); toppers('logout',''); ?> <div id="content"> <div id="flashcontent"> <div class="eastc"> <div id='spotlight'> <div id='featured'> <? if($pgval == 1) { echo " <div class='x-tab' title='Message'>You are currently not logged in </div>"; } else { unset($user); setcookie("user", false); $user = ""; echo " <div class='x-tab' title='Message'>You have been logged out, <br /> We look forward to your next visit! </div>"; } ?> </div> </div> </div> <div class="westc"> <div id="fantimp" style='hidden'><div id="fantasyimpact"></div></div> <div id="rightcolad"> </div> </div> </div> <div id="copy"> </div> <div id="banner"> </div> <? footers(); ?> functions.php: (the lines that matters) function toppers($pg,$user) { echo <<<EOF <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>FantasyWagon - Fantasy Sports New King</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="description" content="Locate a store" /> <meta name="title" content="FantasyWagon - Fantasy Sports New King" /> <meta name="robots" content="index, follow" /> <link rel="shortcut icon" href="" type="image/vnd.microsoft.icon" /> <link rel="icon" href="" type="image/vnd.microsoft.icon" /> <link rel="stylesheet" type="text/css" href="styles/default.css" /> <link rel="stylesheet" type="text/css" href="styles/ext-all.css" /> <link rel="stylesheet" type="text/css" href="styles/xtheme-darkgray.css" /> <script type="text/javascript" src="js/adapter/ext/ext-base.js"></script> <script type="text/javascript" src="js/ext-all.js"></script> EOF; if($pg == 'register') { echo '<script type="text/javascript" src="js/regi.js"></script>'; } else { echo '<script type="text/javascript" src="js/mainBuild.php"></script>'; } echo <<<EOF </head> <body> <div id="main"> <div id="header"> <div class="logo"> <table width="100%" height="100%" cellpadding="0" cellspacing="0" border="0"> <tr> <td width="300" height="150"><img src="images/fwlogo.jpg" width="300" height="150"></td> <td background="images/a2_bg2.gif" width="100%" class="api-title">FantasyWagon.com</td> </tr> </table> </div> </div> <div id="menu"> <div class="tools"> <b>Welcome</b> | EOF; if($user) { echo " ".$user." | <a href='./logout.php'>LogOff </a> \n"; } else { echo " <a href='./register.php'>Join the community</a>\n"; } echo <<<EOF </div> <div class="search"> <form id="search_form" method="get" action="/page.asp"> <img src="images/icon_search.png" alt="Enter your searchword" /> Search <input type="hidden" name="id" id="id" value="79" /> <input name="search" type="text" class="search" id="search" title="Enter your searchword" /> <input name="search_btn" type="submit" class="btn" id="search_btn" value="»" onMouseOver="this.className='btn btnhov'" onMouseOut="this.className='btn'" title="Search" /> </form> </div> <ul> <li><hr /></li> </ul> <ul> <li><a href="index.php" title="FantasyWagon Home Page" onclick="this.blur();" onfocus="this.blur();" class="parent">Home</a></li> <li><a href="#" title="All Fantasy Football Games Home" onclick="this.blur();" onfocus="this.blur();" class="parent">Football</a></li> <li><a href="#" title="All Fantasy Basketball Games Home" onclick="this.blur();" onfocus="this.blur();" class="parent">Basketball</a></li> <li><a href="#" title="All Fantasy Baseball Games Home" onclick="this.blur();" onfocus="this.blur();" class="parent">BaseBall</a></li> <li><a href="#" title="College Basketball Home" onclick="this.blur();" onfocus="this.blur();" class="parent">CollegeBB</a></li> <li><a href="#" title="College Football Home" onclick="this.blur();" onfocus="this.blur();" class="parent">CollegeFB</a></li> <li><a href="#" title="Every thing Soccer" onclick="this.blur();" onfocus="this.blur();" class="parent">Soccer/Futbol</a></li> <li><a href="#" title="Fantasy AutoRacing Home" onclick="this.blur();" onfocus="this.blur();" class="parent">AutoRacing</a></li> <li><a href="#" title="Fantasy Golf" onclick="this.blur();" onfocus="this.blur();" class="parent">Golf</a></li> <li><a href="#" title="All Fantasy Hockey Games Home" onclick="this.blur();" onfocus="this.blur();" class="parent">Hockey</a></li> <li><hr /></li> </ul> <ul> <li><a href="#" title="Community" onclick="this.blur();" onfocus="this.blur();" class="parent">Community</a></li> <li><a href="#" title="Newsroom" onclick="this.blur();" onfocus="this.blur();" class="parent">Newsroom</a></li> <li><a href="#" title="Customer Service" onclick="this.blur();" onfocus="this.blur();" class="parent">Customer Service</a></li> <li><a href="#" title="Select your country and language" onclick="this.blur();" onfocus="this.blur();" class="parent">Country & language</a></li> </ul> <ul><li><hr /></li></ul> </div> EOF; } What could be the problem, how can i make sure that the cookie gets destroyed so the application knows you are no longer logged in. Thank you Link to comment https://forums.phpfreaks.com/topic/112241-headers-already-sent/ Share on other sites More sharing options...
pugboy Posted June 27, 2008 Share Posted June 27, 2008 You set a cookie after you display HTML. That is a no-no Link to comment https://forums.phpfreaks.com/topic/112241-headers-already-sent/#findComment-576271 Share on other sites More sharing options...
mrras25 Posted June 27, 2008 Author Share Posted June 27, 2008 so I should destroy everything MUCH sooner in the logout.php? Link to comment https://forums.phpfreaks.com/topic/112241-headers-already-sent/#findComment-576273 Share on other sites More sharing options...
discomatt Posted June 27, 2008 Share Posted June 27, 2008 Cookies use headers. All headers must be outputted before any markup. A quick solution is object buffering... but I prefer to keep all header-related functions grouped at the top of the script anyways. Link to comment https://forums.phpfreaks.com/topic/112241-headers-already-sent/#findComment-576276 Share on other sites More sharing options...
mrras25 Posted June 27, 2008 Author Share Posted June 27, 2008 Your a mother bloody GENIUS, my eyes are starting to glare over with the amount of code recently written... Thanks again!!!! Problem solved! Link to comment https://forums.phpfreaks.com/topic/112241-headers-already-sent/#findComment-576277 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.