Autoload classes and Check is cookie and sessions still in db

spl_autoload_register(function($class) { require_once 'classes/' . $class . '.php'; }); require_once 'functions/sanitize.php'; if(Cookie::exists(Config::get('remember/cookie_name')) && !Session::exists(Config::get('session/session_name'))) { $hash = Cookie::get(Config::get('remember/cookie_name')); $hashCheck = DB::getInstance()->get('users_sessions', array('hash', '=', $hash)); if($hashCheck->count()) { $user = new User($hashCheck->first()->user_id); $user->login(); }
It autoloads in classes when needed (amazing for big projects)
Under that we have an if statement seeing if the user ticked the "remember me" on login, if so the user will automatically be logged in but if not the user will have to login again.
It checks if the Hash and user session is still in the DB (it gets deleted after 3 days from memory)

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.