Possible Duplicate:
“Warning: Headers already sent” in PHP
I am 100% certain that i'm not outputting any text before setting the headers in this script, but i get this error.
warning: Cannot modify header information - headers already sent by (output started at /home/x/public_html/index.php:4) in /home/x/public_html/core/functions.php on line 25
top of Index.php
<?php
require_once "core/functions.php";
$actions = new Actions();
$actions->isUserLogged($_SERVER['REMOTE_ADDR'], $_COOKIE['cData']);
?>
<!DOCTYPE html>...
core/functions.php
<?php
include_once('connection.php');
class Actions {
private $db;
public function __construct() {
$this->db = new Connection();
$this->db = $this->db->dbConnect( mysql info );
}
public function isUserLogged($currentIP, $cData) {
if(!empty($cData)){ //if cookie is not empty
$getData = $this->db->query("SELECT loggedIP FROM registery WHERE session='".$cData."'")->fetchColumn(); //finding entry in registery.
$loggedIP = $getData['loggedIP'];
if($currentIP == $loggedIP) {return true;} //if that loggedIP and currentIP matces -> proceed.
else { return setcookie('cData','',time()-31536000); //this is where the error points.
return header("location: login.php");} // else unset cookie and redirect to login.
} else {
return header("location: login.php");
}
}
}
?>
connection.php
<?php
error_reporting(E_ALL);
class Connection {
public function dbConnect($server, $username, $password, $db){
return new PDO('mysql:host='.$server.';dbname='.$db, $username, $password);
}
}
?>
if anyone would be so kind to take some time to find my mistake i would appreicate it!
SOLUTION Baba suggested to use "ini_set("display_errors","On");" and that magically solved the problem... i wonder why ty all! :-)