Jump to content


Photo

Warning: session_start(): Cannot send session cache limiter - headers already se


  • Please log in to reply
4 replies to this topic

#1 herbiegrey

herbiegrey
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 17 October 2006 - 09:36 AM

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.

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 2

Warning: 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


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.

<?php
session_start();
session_name('EastDurham');
header("Cache-control: private"); // fix for IE

function 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

<?php
include $_SERVER['DOCUMENT_ROOT'].
        '/layout.php';
// Quick Admin session check 
admin_check();


// Dynamic Form Select Menu
// For Categories
function 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 function
myheader("Modify or Delete News Categories");
// Start switch
switch($_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&amp;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;

}

// Footer
footer();

?>

thanks in advance

#2 radar

radar
  • Members
  • PipPipPip
  • Advanced Member
  • 645 posts
  • LocationSLC

Posted 17 October 2006 - 09:45 AM

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....

#3 herbiegrey

herbiegrey
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 17 October 2006 - 07:45 PM

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?

#4 c4onastick

c4onastick
  • Members
  • PipPipPip
  • Advanced Member
  • 216 posts

Posted 17 October 2006 - 09:22 PM

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.
Regex Tester::Unicode Regex::PHP Function List::MySQL 5.1
"Sorry sweetheart... but this all day sucker is down to the soggy white stick." -- Topper Harley

#5 herbiegrey

herbiegrey
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 18 October 2006 - 10:19 AM

I've tried that as it fixed an earlier problem i had, but it didn't fix this one. Anymore suggestions would be helpful.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users