I have an index.php page that creates a new Login class (login class does all the handling of data,creating session, redirecting, etc)
index.php I create a new login class
require_once('login.class.php');
$login = new Login;
Login constructor looks like this
public function __construct(){
// Start session and open a database connection
session_start();
$this->connectToDB();
}
if the user logs in successfully, I redirect him to securePage.php.
if I do the following on the securePage.php
$test = $_SESSION ['usrData'];
var_export($test->getFirstName());
var_export($test->getLastName());
var_export($test->isAuthorized());
it displays the following error
Fatal error: Call to a member function getFirstName() on a non-object
in /login/securePage.php on line
17
When, however, I put
$login = new Login;
in front of
var_export($test->getFirstName());
var_export($test->getLastName());
var_export($test->isAuthorized());
It works! I dont’ know what gives and if I am doing something wrong because even when I put
session_start();
instead of
$login = new Login;
but it still gives me the error
Fatal error: Call to a member function getFirstName() on a non-object
in /login/securePage.php on line
16
I think it has to do with the variable name. If I am not wrong, in your securePage.php, here is the code:
It should be:
Hope it helps.