Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2003-11-04
4
Medium Priority
?
1,348 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

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…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to count occurrences of each item in an array.
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…
Suggested Courses

618 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