Cannot start session when headers already sent
Jeg har kørt dette script på min lokale maskine, og her kører det fint. Når jeg så lægger det op på min webhotel, så fejler det.Warning: session_start() [function.session-start]: Cannot start session when headers already sent in /var/www/gmonskole.dk/public_html/testkompasset/tk/includes/session.php on line 2
Index.php
<?php
ob_start();
require_once('includes/load.php');
if($session->isUserLoggedIn(true)) { redirect('home.php', false);}
?>
<?php include_once('layouts/header.php'); ?>
<div class="login-page">
<div class="text-center">
<h1>Welcome</h1>
<p>Sign in to start your session</p>
</div>
<?php echo display_msg($msg); ?>
<form method="post" action="auth.php" class="clearfix">
<div class="form-group">
<label for="username" class="control-label">Username</label>
<input type="name" class="form-control" name="username" placeholder="Username">
</div>
<div class="form-group">
<label for="Password" class="control-label">Password</label>
<input type="password" name= "password" class="form-control" placeholder="password">
</div>
<div class="form-group">
<button type="submit" class="btn btn-info pull-right">Login</button>
</div>
</form>
</div>
<?php include_once('layouts/footer.php'); ?>
session.php
<?php
session_start();
class Session {
public $msg;
private $user_is_logged_in = false;
function __construct(){
$this->flash_msg();
$this->userLoginSetup();
}
public function isUserLoggedIn(){
return $this->user_is_logged_in;
}
public function login($user_id){
$_SESSION['user_id'] = $user_id;
}
private function userLoginSetup()
{
if(isset($_SESSION['user_id']))
{
$this->user_is_logged_in = true;
} else {
$this->user_is_logged_in = false;
}
}
public function logout(){
unset($_SESSION['user_id']);
}
public function msg($type ='', $msg =''){
if(!empty($msg)){
if(strlen(trim($type)) == 1){
$type = str_replace( array('d', 'i', 'w','s'), array('danger', 'info', 'warning','success'), $type );
}
$_SESSION['msg'][$type] = $msg;
} else {
return $this->msg;
}
}
private function flash_msg(){
if(isset($_SESSION['msg'])) {
$this->msg = $_SESSION['msg'];
unset($_SESSION['msg']);
} else {
$this->msg;
}
}
}
$session = new Session();
$msg = $session->msg();
?>