?
Solved

Warning: session_start() [function.session-start] Error

Posted on 2003-11-04
4
Medium Priority
?
1,346 Views
Last Modified: 2013-12-12
I'm having the following Errors:

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/httpd/html/display.php:8) in /home/httpd/html/display.php on line 10

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/httpd/html/display.php:8) in /home/httpd/html/display.php on line 10


I've configured my php.ini to the best of my ability for session capabilities, but I am now having these errors in which I don't quite understand .

Can somebody help?
0
Comment
Question by:lyndom2003
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 5

Expert Comment

by:Karitz
ID: 9677691
Please check that before you start the session, you do not have any other output to the browser, even a space. This usually occurs if you are trying to start a session and there is already some output to the browser...in your case there are outputs to the browser at line 8 of your code
0
 

Author Comment

by:lyndom2003
ID: 9677745
Below is my code can you see what is wrong? I can't see any outputs before I start the session.

---------------------getdata.php---------------------------------

<?
session_start();

@ $db = mysql_pconnect("localhost")
         
          if (!$db)
      {
             echo "Error: Could not connect to database!";
                         exit;
          }
     
          mysql_select_db("tiednteased");
          $query = ("SELECT * FROM tiednteased WHERE include = 'yes'AND category = '0'");
          $res = mysql_query($query);
          $num_results = mysql_num_rows($res);
              $result = array();
while($myarray = mysql_fetch_array($res));
{
  array_push($result, array($myarray[0],$myarray[1],$myarray[2],$myarray[3],$myarray[4],$myarray[5]));
}

$_SESSION['total'] = $num_results;  // $i is holding the total number of rows in the $result array
$_SESSION['result'] = $result;  // store your array as well
header("Location: display.php");

?>

------------------------display.php-------------------------

<?
session_start();
 
$results_per_page = 6;
$total = $_SESSION['total'];  // get our variables back from the session
$result = $_SESSION['result'];

if(!isset($_GET['page'])) $page = 0;  
else $page = $_GET['page'];  

echo  "<table width='80%' border='0' align='center'>";
for($i = ($page  * $results_per_page); $i < ($page + 1)*$results_per_page; $i++)
{
  echo  "<tr>";
  echo  "<td height='160'>";
  echo  "<img src=\"$result[$i][2]\">";
  echo  "</td>";
  echo  "<td>";
  echo  "<td><h5>$result[$i][3], $result[$i][4], Member: $result[$i][5] </h5></td>";
  echo  "</td>";
  echo  "</tr>";
}
echo  "</table>";

$page_num = $i - 1;
if($page != 0) echo("<a href=\"display.php?page=".$page_num."\">back</a>");
$page_num = $i + 1;
if($page < $total) echo("<a href=\"display.php?page=".$page_num."\">next</a>");

?>
0
 
LVL 5

Accepted Solution

by:
Karitz earned 2000 total points
ID: 9677953
check to see that you do not have even a space before <?

your line 10 in display.php is a an output to the browser

echo  "<table width='80%' border='0' align='center'>";

Make sure you have no white space before the <? even a space will cause an error.

also check to ensure that your save as option is ok..the editor you are using might be adding some code.

Otherwise my guess is that the error is caused by your starting the session twice when alread you have some out put in the browser. Try and remove session_start() from your display.php and see what happens
0
 

Author Comment

by:lyndom2003
ID: 9678083
Yep the problem was due to the session_start() being used twice. Thats great cheers.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question