Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

Login/Logout with Redirect

In response to I created this sample web app.

git clone git://
cd Slim-ContextSensitiveLoginLogout
curl -s | php
php composer.phar install
php -S   # <== assumes PHP 5.4 (built in dev server)

Launch browser to

This application uses route middleware for authentication and a slim.before.dispatch hook to set a $user variable for all views if in fact the user is logged in.

Public pages

From any public page you can click Login and it will redirect to the login page and upon successful login redirect back to the previously browsed page. This is done partly via javascript to capture the current url on the Login click and via sessions (cookie) to store the url to redirect to.

Private pages

This also works if you try to visit a private page as well. If you are not logged in and try to visit it will see that you are not authenticated, store that url and forward you onto the login page. Then again upon successful login redirect you back to the requested private page. This is all done via sessions (cookies).

Page navigation

The page navigation only shows the Login or Logout as needed and shows private pages only after the user is logged in.


If you have no idea what I am talking about, first visit Slim Framework.


No releases published


No packages published