Solved

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

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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 …

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now