joeysarsenal Posted October 4, 2007 Share Posted October 4, 2007 I had my html code saved as .html . Then saved the output .php thinking it would be easier then i got a whole bunch of session problems Below is the errors i get. Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\htdocs\Finalised\shopping.php: in C:\Program Files\Apache Group\Apache2\htdocs\Finalised\plaincart\library\config.php on line 7 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\Program Files\Apache Group\Apache2\htdocs\Finalised\shopping.php: in C:\Program Files\Apache Group\Apache2\htdocs\Finalised\plaincart\library\config.php on line 7 And also below are the 2 pages of code index.php <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta name="generator" content="HTML Tidy for Linux (vers 1 September 2005), see www.w3.org"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Tedley's Fishing Chaters > shopping</title> <script language="JavaScript" type="text/JavaScript"> <!-- function MM_swapImgRestore() { //v3.0 var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc; } function MM_preloadImages() { //v3.0 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array(); var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++) if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}} } function MM_findObj(n, d) { //v4.01 var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) { d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n]; for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); if(!x && d.getElementById) x=d.getElementById(n); return x; } function MM_swapImage() { //v3.0 var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3) if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];} } //--> </script> <meta name="teds" content="teds"> <style type="text/css"> body { background-color: #E5E5E5; } div.c5 {text-align: right} p.c4 {text-align: right} p.c3 {text-align: center} div.c2 {text-align: center} div.c1 {text-align: left} </style> </head> <body onload="MM_preloadImages('home_tabyellow.png','aboutus_tabyellow.png','login_tabyellow.png','contactus_tabyellow.png','shopping_tabellow.png')"> <div class="c2"> <table width="834" border="0" align="center" cellpadding="0" cellspacing="0"><!-- MSTableType="layout" --> <tr align="center"> <td height="84" valign="top" bgcolor="#FFFFFF"><img src="fish.png" width="140" height="84" align="top" alt="** PLEASE DESCRIBE THIS IMAGE **"></td> <td height="84" colspan="7" valign="top" bgcolor="#FFFFFF"> <div class="c1"><img src="banner4.gif" width="655" height="84" alt="** PLEASE DESCRIBE THIS IMAGE **"></div> </td> </tr> <tr> <td width="181" height="586" rowspan="2" valign="top" bgcolor="#FFFFFF"><img src="sidetab1.png" width="181" height="586" align="top" alt="** PLEASE DESCRIBE THIS IMAGE **"></td> <td width="93" height="23" valign="top" bgcolor="#FFFFFF"><a href="index6.htm" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('home','','home_tabyellow.png',1)"><img src="home_tab.png" alt="home" name="home" width="93" height="23" border="0"></a></td> <td width="93" valign="top" bgcolor="#FFFFFF"><a href="aboutus.htm" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('about us','','aboutus_tabyellow.png',1)"><img src="aboutus_tab.png" alt="about us" name="about us" width="93" height="23" border="0"></a></td> <td width="93" valign="top" bgcolor="#FFFFFF"><a href="shopping.htm" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('shopping','','shopping_tabellow.png',1)"><img src="shopping_tab.png" alt="shopping" name="shopping" width="93" height="23" border="0"></a></td> <td width="93" valign="top" bgcolor="#FFFFFF"><a href="contactus.htm" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('contact us','','contactus_tabyellow.png',1)"><img src="contactus_tab.png" alt="contact us" name="contact us" width="93" height="23" border="0"></a></td> <td width="93" valign="top" bgcolor="#FFFFFF"><a href="login.htm" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('login','','login_tabyellow.png',1)"><img src="login_tab.png" alt="login" name="login" width="93" height="23" border="0"></a></td> <td width="187" valign="top" bgcolor="#FFFFFF"><img src="rightshift_tab.png" width="187" height="23" alt="** PLEASE DESCRIBE THIS IMAGE **"></td> <td width="1" valign="top" bgcolor="#FFFFFF"> </td> </tr> <tr> <td height="532" colspan="7" valign="top" bgcolor="#FFFFFF"> <table width="651" border="0" cellpadding="2" cellspacing="1" bgcolor="#FFFFFF"><!-- MSTableType="layout" --> <tr bgcolor="#FFFFFF"> <td height="55" colspan="3" valign="top"> <div class="c1"> </div> </td> </tr> <tr bgcolor="#FFFFFF"> <td height="72" colspan="3" valign="top"> <div class="c2"></div> </td> </tr> <tr bgcolor="#FFFFFF"> <td width="38" height="358" valign="top"> <div class="c2"></div> <p class="c3"></p> </td> <td width="349" valign="top"> <div class="c2"> <p class="c4"> </p> <?php require_once 'plaincart/library/config.php'; require_once 'plaincart/library/category-functions.php'; require_once 'plaincart/library/product-functions.php'; require_once 'plaincart/library/cart-functions.php'; $_SESSION['shop_return_url'] = $_SERVER['REQUEST_URI']; $catId = (isset($_GET['c']) && $_GET['c'] != '1') ? $_GET['c'] : 0; $pdId = (isset($_GET['p']) && $_GET['p'] != '') ? $_GET['p'] : 0; require_once 'plaincart/include/header.php'; ?> <table width="780" border="1" align="center" cellpadding="0" cellspacing="0"> <tr> <td colspan="3"> <?php require_once 'plaincart/include/top.php'; ?> </td> </tr> <tr valign="top"> <td width="150" height="400" id="leftnav"> <?php require_once 'plaincart/include/leftNav.php'; ?> </td> <td> <?php if ($pdId) { require_once 'plaincart/include/productDetail.php'; } else if ($catId) { require_once 'plaincart/include/productList.php'; } else { require_once 'plaincart/include/categoryList.php'; } ?> </td> <td width="130" align="center"><?php require_once 'plaincart/include/miniCart.php'; ?></td> </tr> </table> <?php require_once 'plaincart/include/footer.php'; ?> </div> <div class="c5"> <p> </p> </div> </td> <td width="248" valign="top"> <p class="c3"> </p> </td> </tr> <tr bgcolor="#FFFFFF"> <td height="154" colspan="3" valign="top"> </td> </tr> </table> </td> </tr> </table> </div> <p> <a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-html401-blue" alt="Valid HTML 4.01 Transitional" height="31" width="88"></a> </p> </body> </html> config.php <?php ini_set('display_errors', 'On'); //ob_start("ob_gzhandler"); error_reporting(E_ALL); // start the session session_start(); // database connection config $dbHost = 'localhost'; $dbUser = 'root'; $dbPass = ''; $dbName = 'plaincart'; // setting up the web root and server root for // this shopping cart application $thisFile = str_replace('\\', '/', __FILE__); $docRoot = $_SERVER['DOCUMENT_ROOT']; $webRoot = str_replace(array($docRoot, 'library/config.php'), '', $thisFile); $srvRoot = str_replace('library/config.php', '', $thisFile); define('WEB_ROOT', $webRoot); define('SRV_ROOT', $srvRoot); // these are the directories where we will store all // category and product images define('CATEGORY_IMAGE_DIR', 'images/category/'); define('PRODUCT_IMAGE_DIR', 'images/product/'); // some size limitation for the category // and product images // all category image width must not // exceed 75 pixels define('MAX_CATEGORY_IMAGE_WIDTH', 75); // do we need to limit the product image width? // setting this value to 'true' is recommended define('LIMIT_PRODUCT_WIDTH', true); // maximum width for all product image define('MAX_PRODUCT_IMAGE_WIDTH', 300); // the width for product thumbnail define('THUMBNAIL_WIDTH', 75); if (!get_magic_quotes_gpc()) { if (isset($_POST)) { foreach ($_POST as $key => $value) { $_POST[$key] = trim(addslashes($value)); } } if (isset($_GET)) { foreach ($_GET as $key => $value) { $_GET[$key] = trim(addslashes($value)); } } } // since all page will require a database access // and the common library is also used by all // it's logical to load these library here require_once 'database.php'; require_once 'common.php'; // get the shop configuration ( name, addres, etc ), all page need it $shopConfig = getShopConfig(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/71751-solved-session-problems/ Share on other sites More sharing options...
teng84 Posted October 4, 2007 Share Posted October 4, 2007 this has been answered thousands of times here put your session start on the very top most of the page right before <? without any spaces Quote Link to comment https://forums.phpfreaks.com/topic/71751-solved-session-problems/#findComment-361338 Share on other sites More sharing options...
joeysarsenal Posted October 4, 2007 Author Share Posted October 4, 2007 Thanks for the help, ill try it once i get home. Just wondering why would the session start not being at the time make such a difference. Quote Link to comment https://forums.phpfreaks.com/topic/71751-solved-session-problems/#findComment-361428 Share on other sites More sharing options...
corbin Posted October 4, 2007 Share Posted October 4, 2007 http://www.phpfreaks.com/forums/index.php/topic,37442.0.html to be more specific ;p. Also, it helps (for me anyway) to know why a problem surfaces, not just how to fix it. When a session is started, a request is sent to the client (in most cases Firefox, Internet Explorer, so on) to get a value (which I will refer to as sessid) from a cookie. If said sessid exists, the client will send it back to the server, and if things work out, the data from the file which goes with the sessid (assuming files are being used for the sessions) will be loaded into the $_SESSIONS array. If the sessid isn't found client side, the server generates a sessid and tells the client to set a cookie with it. What's this have to do with a header? The headers are a block of data sent to the server or client. For example, the headers to get the page http://www.google.com/ would look something like: GET / HTTP/1.1 Host: www.google.com That tells the server at google.com that I want / from it, and the site is www.google.com (since the google.com when connecting to the server would be lost in the DNS to IP phase). The server might send back something like: HTTP/1.1 200 OK Cache-Control: private Content-Type: text/html; charset=ISO-8859-1 Set-Cookie: PREF=ID=064477103b1ca1c6:TM=1191472339:LM=1191472339:S=NBhjmVN6cJxWg 8rz; expires=Sat, 03-Oct-2009 04:32:19 GMT; path=/; domain=.google.com Server: gws Transfer-Encoding: chunked Date: Thu, 04 Oct 2007 04:32:19 GMT That just says some information about the page such as what type of data it is, how the client should cache it so on.... Anyway the important part is, headers can't be sent by PHP (or interpreted by a client) once data besides a header has been sent. For example if you had: HTTP/1.1 200 OK Cache-Control: private <a href="http://google.com/">lol</a> Content-Type: text/html; charset=ISO-8859-1 Set-Cookie: PREF=ID=064477103b1ca1c6:TM=1191472339:LM=1191472339:S=NBhjmVN6cJxWg 8rz; expires=Sat, 03-Oct-2009 04:32:19 GMT; path=/; domain=.google.com Server: gws Transfer-Encoding: chunked Date: Thu, 04 Oct 2007 04:32:19 GMT The client would just be like 'uhhh wtf?' So, the header to set a cookie must be sent before content is sent. --------- Wow... I should find something better to do with my time.... lol Quote Link to comment https://forums.phpfreaks.com/topic/71751-solved-session-problems/#findComment-361449 Share on other sites More sharing options...
joeysarsenal Posted October 4, 2007 Author Share Posted October 4, 2007 No your right, thanks for the time you took to type that. I understand that sessions are to do with cookies, but there a little harder then i thought to understand. Thanks for explaining. Another thing it didnt work, when it was outside of the <? then nothing happened. Quote Link to comment https://forums.phpfreaks.com/topic/71751-solved-session-problems/#findComment-361458 Share on other sites More sharing options...
Mad Mick Posted October 4, 2007 Share Posted October 4, 2007 I think he meant immediately after the <?php - should be the first line of the php code. Quote Link to comment https://forums.phpfreaks.com/topic/71751-solved-session-problems/#findComment-361528 Share on other sites More sharing options...
joeysarsenal Posted October 4, 2007 Author Share Posted October 4, 2007 i still get the same error even if i put it as <?php session_start(); Quote Link to comment https://forums.phpfreaks.com/topic/71751-solved-session-problems/#findComment-361535 Share on other sites More sharing options...
joeysarsenal Posted October 4, 2007 Author Share Posted October 4, 2007 ive tried a couple things, and had no luck. Anyone got any ideas. Quote Link to comment https://forums.phpfreaks.com/topic/71751-solved-session-problems/#findComment-361669 Share on other sites More sharing options...
trq Posted October 4, 2007 Share Posted October 4, 2007 Put this at the very top of your page. Very first line. <?php session_start(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/71751-solved-session-problems/#findComment-361696 Share on other sites More sharing options...
Mad Mick Posted October 4, 2007 Share Posted October 4, 2007 Don't forget that config.php effectively appears in the middle of index.php when the "require_once" appears. So all the stuff you output in index.php is before the session_start() as far as the overall script is concerned. At least I think I'm right in saying that, more knowledgeable people will correct me I'm sure... Quote Link to comment https://forums.phpfreaks.com/topic/71751-solved-session-problems/#findComment-361715 Share on other sites More sharing options...
joeysarsenal Posted October 4, 2007 Author Share Posted October 4, 2007 Thank you when i put that at the top of my index.php even above the doctype i got it worked. Did i do it right? <?php session_start(); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta name="generator" content="HTML"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Tedley's Fishing Chaters > shopping</title> Quote Link to comment https://forums.phpfreaks.com/topic/71751-solved-session-problems/#findComment-362021 Share on other sites More sharing options...
joeysarsenal Posted October 5, 2007 Author Share Posted October 5, 2007 I had someone tell me that it would be wrong with the session start above the doctype. What you guys think? Quote Link to comment https://forums.phpfreaks.com/topic/71751-solved-session-problems/#findComment-362189 Share on other sites More sharing options...
Aureole Posted October 5, 2007 Share Posted October 5, 2007 That person is misinformed, session_start(); comes before ANYTHING else, even the doctype... He is right in a sense in that nothing should come before the doctype but the session_start(); is not going to show up in the source code so technically it's not before the doctype so it's an exception... If you put like echo('Lol...'); before the doctype then yes that would be incorrect. Quote Link to comment https://forums.phpfreaks.com/topic/71751-solved-session-problems/#findComment-362191 Share on other sites More sharing options...
teng84 Posted October 5, 2007 Share Posted October 5, 2007 I had someone tell me that it would be wrong with the session start above the doctype. What you guys think? who told you that??? lol Quote Link to comment https://forums.phpfreaks.com/topic/71751-solved-session-problems/#findComment-362196 Share on other sites More sharing options...
joeysarsenal Posted October 5, 2007 Author Share Posted October 5, 2007 thanks guys uve been really helpfull. Quote Link to comment https://forums.phpfreaks.com/topic/71751-solved-session-problems/#findComment-362199 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.