Solved

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

Posted on 2003-11-04
4
1,343 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
  • 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 500 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Log in through ID 5 36
Adding additional variables to key => value association 17 37
Need guidance for special auto increment values 2 20
Survey branching tutorial 11 37
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
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 count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

685 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