Jump to content

Headers already sent, but how?


russia5

Recommended Posts

I uploaded my script into two different folders on my site.  I then got a "Headers already sent erorr"  I then deleted one of the scripts.  I am still getting the error.  Does anyone have a guess why?

 

This is index.php

 


<?php
  include ('book_sc_fns.php');
  // The shopping cart needs sessions, so start one
  session_start();
  do_html_header('Welcome to Book-O-Rama');

  echo '<p>Please choose a category:</p>';

  // get categories out of database
  $cat_array = get_categories();

  // display as links to cat pages
  display_categories($cat_array);

  // if logged in as admin, show add, delete, edit cat links
  if(isset($_SESSION['admin_user']))
  {
    display_button('admin.php', 'admin-menu', 'Admin Menu');
  }
  do_html_footer();
?>


 

This is book_sc_fns.php

 

<?php

  include_once('db_fns.php');
  include_once('data_valid_fns.php');
  include_once('output_fns.php');
  include_once('book_fns.php');
  include_once('user_auth_fns.php');
  include_once('admin_fns.php');
  include_once('order_fns.php');

?>

 

And here is the error on the page that was produced:

 


Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/russia5/public_html/27/db_fns.php:24) in /home/russia5/public_html/27/index.php on line 4

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/russia5/public_html/27/db_fns.php:24) in /home/russia5/public_html/27/index.php on line 4


Link to comment
Share on other sites

Yes indeed!  Here it is.

 


<?php

function db_connect()
{
   $result = mysql_connect("localhost", "abc_usrid", "password");
mysql_select_db("booksc"); 
   if (!$result)
      return false;
   return $result;
}

function db_result_to_array($result)
{
   $res_array = array();

   for ($count=0; $row = $result->fetch_assoc(); $count++)
     $res_array[$count] = $row;

   return $res_array;
}

?>

Link to comment
Share on other sites

You cannot have any whitespace, lines or other output to the browser before the php start-tag

 

OK:

------------------------------------------------------------------

<?php

session_start();

 

 

ERROR:

------------------------------------------------------------------

 

<?php

session_start();

 

 

 

Means it's ok to put session_start() 'anyhwhere' as long as no output is done before it.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.