简体   繁体   中英

“session_start(): Cannot send session cache limiter - headers already sent” keep coming even after session_start() already on top

I got "Warning: session_start(): Cannot send session cache limiter - headers already sent". I cannot put the session_start() on top because i'm using "use Phppot\DataSource" and it will not work if i change their position. The code that i made was like this:

<?php
use Phppot\DataSource;
session_start();
require_once 'web.php';
?>

Can someone help me solve this error? Thanks!

move session_start() under <?php

sessions and other headers have to be set before anything is broadcasted, and it seems phppot is broadcasting something looking at the error.

You can actually check what is causing headers to be sent: https://www.php.net/manual/en/function.headers-sent.php

So for debugging you could do something like

<?php
use xxx;

if (headers_sent($file, $line)) {
    die("Headers unexpectedly sent from {$file}::{$line}");
}
session_start();

Note that session_start() as your first statement is generally not the proper solution to these kinds of issues...

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