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
https://forums.phpfreaks.com/topic/37501-headers-already-sent-but-how/
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;
}

?>

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.

Archived

This topic is now archived and is closed to further replies.

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