The Slim Framework support forum has moved to This Tender forum is no longer maintained or monitored.

Login Check throws stop exception

booster's Avatar


10 Sep, 2015 12:49 PM

I'm using Slim for my first time and want to create a REST api.
But I only want logged in users to have acces.
I have another class that checks if the user is logged in.

My index.php looks like this:

use \Slim\Slim;
require_once(__DIR__ . "/vendor/autoload.php");
require_once(__DIR__ . "/../php/init.php");
    $app = new Slim();
    /* ... my routes ... */
    //throw no exception
    $app->notFound(function() use ($app){
        $app->halt(404, "Not found");
    //Throws stop exception
    if( !AccountManager::isLoggedIn() ){
        $app->halt(403, "No Access");
} catch(Exception $e){ echo "<pre>", var_dump($e->getTrace()), "</pre>"; }

The isLoggedIn methods looks like the following:

public static function isLoggedIn(){
        if( !empty($_SESSION["username"]) && !empty($_SESSION["data"]) ){
            if( $_SESSION["data"] === md5($_SERVER["HTTP_USER_AGENT"]) ){
                return true;
        return false;
  1. 1 Posted by booster on 11 Sep, 2015 01:44 PM

    booster's Avatar

    Solved it by using the slim.before hook.

  2. booster closed this discussion on 11 Sep, 2015 01:44 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac