Cant understand why Im still having this warning. My session_start() starts at the top of the page. I look all the previous post and they all said that my session_start() is at the wrong position. Is this warning occurring because of using session superglobal?
ERROR
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
}
?>
Also I echo my logout.php link in index.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>';}?>