0

I am not sure why, it gave me this error, and my session_start(); is already at the first line. The codes work before, but i altered the sql query, then it gave me that error.

Here is my code.

<?php

ini_set('display_errors', 1); error_reporting(E_ALL);

session_start();
include 'connect.php';







$_SESSION['username'];
$_SESSION['id'];
$userid = $_SESSION['id'];


//Using session username to pull out variables from Table

$result=mysqli_query($con,"SELECT ......);





while ($row1 = mysqli_fetch_assoc($result))

        {

   $output[] = $row1;
        }
        if (!empty($output)){
        echo json_encode( $output );}
        else{
            echo json_encode( [] );
        }
?> 
NikiC
  • 100,734
  • 37
  • 191
  • 225
Benyaman
  • 451
  • 2
  • 10
  • 25

2 Answers2

2

According to the PHP manual, the error happens when some sort of output has happened before session_start is called. This is especially so if you're displaying errors. This could be a space before the <?php tags at the top of the document, or it could be because of a warning from deprecated code, or from missing variables or an error from a missing ; or other type of character. The best thing to do is to log any errors to a file and then review the file after you execute.

Try moving the session_start() to the top of the document and also check that session_start() isn't called by any other file or class or function anywhere else in your code.

Justin Mitchell
  • 339
  • 1
  • 5
1

"Cannot send session cache limiter - headers already sent"

"Headers already sent" means that your PHP script already sent the HTTP headers, and as such > it can't make modifications to them now.

Check that you don't send ANY content before calling session_start. Better yet, just make > "session_start" the first thing you do in your PHP file (so put it at the absolute beginning, > before all HTML etc).

Hope it helps.

Community
  • 1
  • 1
Tyralcori
  • 1,079
  • 13
  • 33