I use the following code as a custom file without the common files. I know - that’s not recommended - but I need some custom files that return data in a specific format. I include this file in all of them to deny access to users who aren’t logged in.
The function IsLoggedIn()
keeps returning this error:
Fatal error: Uncaught Error: Call to a member function get() on null in C:\xampp\htdocs\myapp\app\src\phpfn.php:4982
It seems that, even though I start a session, no session is being created.
My code:
/* Use defaults from index.php to get access to database and PHPMaker functions */
namespace PHPMaker2025\myapp;
use PHPMaker2025\myapp\{UserProfile, Language, AdvancedSecurity, Timer, HttpErrorHandler};
$RELATIVE_PATH = "../";
require_once $RELATIVE_PATH . "vendor/autoload.php";
require_once $RELATIVE_PATH . "src/constants.php";
require_once $RELATIVE_PATH . "src/config.php";
require_once $RELATIVE_PATH . "src/phpfn.php";
require_once $RELATIVE_PATH . "src/userfn.php";
// Start Session if not started yet
if (session_status() !== PHP_SESSION_ACTIVE) {
session_start(); // Init session data
}
/* Deny access if user is not logged in */
if(!IsLoggedIn()) die('Not logged in. Permission denied.');
Does anybody know why or have a working example?