不明白为什么我仍然有这个警告。我的session_start()从页面顶部开始。我查看了之前的所有帖子,他们都说我的session_start()处于错误的位置。是否因为使用会话超全局而发生此警告?
错误
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/xxx/xxx/xxx/login/logout.php:1) in /home/xxx/xxx/xxx/login/config.php on line 3
Warning: Cannot modify header information - headers already sent by (output started at /home/xxx/xxx/xxx/login/logout.php:1) in /home/xxx/xxx/xxx/login/logout.php on line 8`
CONFIG.PHP
<?php
session_start();
//error_reporting(0);
/* Andmebaasi konfiguratsioon */
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'xxx');
define('DB_PASSWORD', 'xxx');
define('DB_DATABASE', 'xxx');
define("BASE_URL", "http://www.xxx.ee/xxx/"); // Määrame ära alus urli, et oleks lihtsam linkida lehti
function getDB()
{
$dbhost=DB_SERVER;
$dbuser=DB_USERNAME;
$dbpass=DB_PASSWORD;
$dbname=DB_DATABASE;
try {
$dbConnection = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass); //Loo ühendus andmebaasiga
$dbConnection->exec("set names utf8"); //Teeb tähed utf8 formaati
$dbConnection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); //Seadistab veamoodi
return $dbConnection; //Tagastab andmebaasi väärtuse
}
catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage(); //Teatab et funktsioon ei õnnestunud tänu veale
}
}
?>
Logout.php
<?php
require_once('config.php'); // Kaasame configu faili
$session_uid=''; // Muutja sessioon id võrdub tühi väärtus ehk NULL
$_SESSION['uid']=''; // Sessiooni id võrdub tühi väärtus ehk NULL
if(empty($session_uid) && empty($_SESSION['uid'])) //Kui sesioonid väärtused on tühjad, siis...
{ //Toimub välja logimine, sest sessiooni muutjad on tühjad
$url='index.php';
header("Location: $url"); // URLi suunamine
}
?>
我也在index.php
中回显我的logout.php链接 <?php if(empty($_SESSION['uid']))
{echo '<li class="nav_li" style="float:right"><a id="login_button">Logi sisse</a></li>
<li class="nav_li" style="float:right"><a id="register_button">Registeeru</a>';}
else{echo'<li class="nav_li" style="float:right"><a href="'. BASE_URL.'login/logout.php">Logout</a></li>';}?>