简体   繁体   中英

PHP - SQLite Issue: Cannot modify header information - headers already sent by

I've spent far too much time trying to solve this issue. None of the fixes I've found have worked thus far. I would really appreciate any help.

The issue occurs when I attempt to redirect to a new page after checking login information. This is my code that runs after the login button is pressed:

<?php
  ob_start();
  session_start();
  $database = new SQLite3('newdb.db');
  $fname=$_POST['fname'];
  $lname=$_POST['lname'];

  $sql = "SELECT * FROM guests WHERE fname = '$fname' and lname = '$lname'";
  $result= $database->query($sql);
  $row = $result->fetchArray();
  if (!empty($row)){
      header ("Location: home.php");
      die();
  }
  else {echo "NOPE";}
  $database->close();
?>
<?php ob_flush(); ?>

As you can see, I have tried adding in ob_start/flush which hasn't helped. I've also checked for extra white space and have tried multiple ways of writing the header code. Nothing has worked.

I assume I am overlooking something. Any help would be greatly appreciated.

It's also probably worth mentioning that the error message says it's coming from my check.php page on line 1. Although nothing seems to be there.

Take the source view of your page, look at the top and make sure that there is no blank lines exist. If a blank line is coming then remove this and try again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM