Last active
August 29, 2015 14:01
-
-
Save chartrandf/405048daac5e02c5672c to your computer and use it in GitHub Desktop.
Snippet - Users timeout in Laravel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// If the user isn't logged in, don't do anything, just return | |
if(!Auth::user()) { | |
return false; | |
} | |
$now = new DateTime(); | |
$last_activity = Auth::user()->last_activity; | |
$diff = ( date diff magic ) | |
// Or whatever value in whatever format is needed... like I said, pseudo code | |
$timeout = "40"; | |
if($diff > $timeout) { | |
Auth::logout(); | |
return Redirect::to('login')->with('timeout','Session timed out, please login again.'); | |
} | |
// TImeout has not occurred, update last_activity | |
Auth::user()->last_activity = $now; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment