I am having trouble with the following code and error:
Error:
Warning: Cannot add header information - headers already sent by (output started at C:\Intranet\php\login\session\session.class.php:40) in C:\Intranet\php\login\doLogin.class.php on line 72
Code:
/ SESSION CLASS /
<?php
session_start();
class Session
{
function Session()
{
$this->_registerSession();
}
/ Register the session variables /
function _registerSession()
{
/ Create the new session variables /
session_register( 'username' );
session_register( 'privilege' );
session_register( 'firstname' );
session_register( 'logged' );
/ Register the default values /
$SESSION['username'] = NULL;
$SESSION['privilege'] = NULL;
$SESSION['firstname'] = NULL;
$SESSION['logged'] = false;
}
/ Sets the session with $username, $privilege, $firstname and $logged /
function setSession( $username, $privilege, $firstname, $logged )
{
$SESSION['username'] = $username;
$SESSION['privilege'] = $privilege;
$SESSION['firstname'] = $firstname;
$SESSION['logged'] = $logged;
}
}//End Session
?> //LINE 40 HERE
/ DOLOGIN CLASS /
/ Performs the required login, sets the session variables and updates the users last login time /
function _doLogin( $username, $privilege, $firstname )
{
/ Set the session variables username, privilege, firstname and set logged to now be true /
//$this->_session->setSession( $username, $privilege, $firstname, 'true' );
/ Update the last Login /
$this->_updateLastLogin( $username );
/ Redirect to the home page /
header( "location: ../content/index.php" );
}
The only call to class session is at the beggining of class DOLOGIN when it is instantiated. I know that this is sending header information to the browser hence the error but can see no way round this, I have tried ob_flush etc - but does not seem to work! Any suggestion welcome.
Thanks