herbiegrey Posted October 17, 2006 Share Posted October 17, 2006 Hello, i'm new to php and phpfreaks, so hello!I've got a small error that you guys probably think is trivial. I'm working through a book i bought that is endorsed by phpfreaks, and it's called "creating interactive websites with php and web services"I've got two errors although i've followed the book exactly. [b]Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/fhlinux183/e/east-durham.co.uk/user/htdocs/admin/mod_news_category.php:1) in /home/fhlinux183/e/east-durham.co.uk/user/htdocs/includes/session.php on line 2Warning: Cannot modify header information - headers already sent by (output started at /home/fhlinux183/e/east-durham.co.uk/user/htdocs/admin/mod_news_category.php:1) in /home/fhlinux183/e/east-durham.co.uk/user/htdocs/includes/session.php on line 4[/b]The lines 2 and 4 are on my session file and i can't see any errors in it but i'll post the code. <?phpsession_start();session_name('EastDurham');header("Cache-control: private"); // fix for IEfunction login_check(){if($_SESSION['login'] !=TRUE){myheader("Login Required");include $_SERVER['DOCUMENT_ROOT'].'/html/forms/login_form.html';footer();exit();}}function admin_check(){ if($_SESSION['admin_access'] != TRUE){ myheader("Access Denied!"); echo "<center>This area is restricted". " for website administrators!"; footer(); exit(); }}?>here is the code of the page that the error appears on<?phpinclude $_SERVER['DOCUMENT_ROOT']. '/layout.php'; // Quick Admin session check admin_check();// Dynamic Form Select Menu// For Categoriesfunction cat_list($selected){ // Perform the query $sql = mysql_query("SELECT * FROM news_categories"); // Begin select menu echo "<select name=\"cat_id\">\n"; echo "<option value=\"NULL\">Please Select</option>\n"; // Do the loop for the categories while($row = mysql_fetch_array($sql)){ echo "<option value=\"". stripslashes($row[cat_id])."\""; // if $selected is equal // to current row, select // this item in menu. if($selected == $row[cat_id]){ echo "selected"; } echo ">".stripslashes($row[cat_name]). "</option>\n"; } // Close select statement echo "</select>\n";}// Initiate myheader functionmyheader("Modify or Delete News Categories");// Start switchswitch($_REQUEST['req']){ // Modify category form case "mod_category": $sql = mysql_query("SELECT * FROM news_categories WHERE cat_id='{$_POST['cat_id']}'"); $row = mysql_fetch_assoc($sql); include $_SERVER['DOCUMENT_ROOT']. '/html/forms/mod_news_category_form.html'; break; // Modify category query case "update_category": $sql = mysql_query("UPDATE news_categories SET cat_name='{$_POST['cat_name']}', cat_description='{$_POST['cat_description']}' WHERE cat_id='{$_POST['cat_id']}'") or die (mysql_error()); if(!$sql){ echo "Error performing query: ". mysql_error(); } else { echo '<p align="center">Category Updated!</p>'; echo '<p align="center">'. '<a href="/admin/mod_news_category.php">'. 'Modify Another Category</a>'; } break; // Delete category confirmation case "del_category": echo '<p align="center">Are you sure '. 'you want to delete this category?'. '</p>'; echo '<p align="center">'. '<a href="/admin/mod_news_category.php?req=delete_category&cat_id=' .$_POST['cat_id'].'">Yes</a> '. '| <a href="/admin/mod_news_category.php">No</a></p>'; break; // Delete category query case "delete_category": $sql = mysql_query("DELETE FROM news_categories WHERE cat_id='{$_REQUEST['cat_id']}'"); if(!$sql){ echo 'Error performing DELETE query: '. mysql_error(); } else { echo '<p align="center">Category Deleted!</p>'; echo '<p align="center">'. '<a href="/admin/mod_news_category.php">'. 'Modify another category</a></p>'; } break; // Modify and Delete category forms default: include $_SERVER['DOCUMENT_ROOT']. '/html/forms/mod_news_category_index.html'; break;}// Footerfooter();?>thanks in advance Quote Link to comment Share on other sites More sharing options...
radar Posted October 17, 2006 Share Posted October 17, 2006 Do me a favor... wrap your code in [*code*] [*/code*] tags...Though this is 100% of the time going to be your error when working with session (i've been programming php for a while still not the best but im good)... Somewhere in one of your files you are outputting some HTML before a session variable...Now I am willing to bet that if you swap these two lines.. it'll work.. include $_SERVER['DOCUMENT_ROOT']. '/layout.php'; // Quick Admin session check admin_check();make that read in your file..// Quick Admin session check admin_check();include $_SERVER['DOCUMENT_ROOT']. '/layout.php'; See -- I'm guessing that will work -- and the reason why is because whats inside the layout.php? probably a lot of HTML -- and since the HTML has already been called -- you can no longer send header information because the page has already loaded.... Quote Link to comment Share on other sites More sharing options...
herbiegrey Posted October 17, 2006 Author Share Posted October 17, 2006 This didn't work as the layout file includes the commands to call the session file plus others. The admin_check is refering to the session file, so if you know the code that will link this function to the file directly then it may help? Quote Link to comment Share on other sites More sharing options...
c4onastick Posted October 17, 2006 Share Posted October 17, 2006 I had the same problem. The session_start fuction is very sensitive to whitespace outside of the php tags. I had a couple of extra returns outside my closing '?>' tag, after removing them, it worked fine. If you're coding in some sort of software suite for php, they may be put there by the software. I use nano, (you can use notepad, not wordpad, in windows) to remove the whitespace at the end. Quote Link to comment Share on other sites More sharing options...
herbiegrey Posted October 18, 2006 Author Share Posted October 18, 2006 I've tried that as it fixed an earlier problem i had, but it didn't fix this one. Anymore suggestions would be helpful. 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.