Solved

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

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

688 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