Destiny Destiny - 12 days ago 7
PHP Question

Call to a member function is_loggedin() on null on line 4

I seem to be getting these two errors regarding my

Index.php
page


Notice: undefined variable: user in C:\xampp\htdocs\Index.php on line 4

Fatal error: Call to a member function is_loggedin() on null in C:\xampp\htdocs\Index.php on line 4


This is the code I am pointed to

<?php

require_once 'Dbconfig.php';

If($user->is_loggedin() ==!"")
{
$user->redirect('home.php');
}

?>

Answer

The error says that the user variable is null. The issue seems to be that the user variable is not declared in scope of this function. I.e. in index.php

Another possibility is that you have not handled the condition where the user variable is going to be null.

If the first one is the case, make sure that the user variable is declared and assigned with the user properties.

If the second one is the case. Check the variable for null and redirect to login when the user is null.