php - what is the best way to handle database querying before any page is loaded? -
i'm using laravel 4 framework , though i'm open doing non-laravel way, if need be. logged in users maintained in database 'active_users', if record deleted database, want phone call auth::logout(). best way ?
these options have considered : 1. event (not sure how go it) 2. using ajax poll script queries db 3. using (before) filter. 4.using table based sessions <= seems attractive option.
if there improve different way this, please allow me know, give thanks you.
this rather simple. highly assume got server side execution on every page can handle server-side code, including session handling.
you need ajax if you'd storing users in client local storage assume you're handling user session on server.
just create function returns bool
value true
if user exists, false
otherwise. if function returns false destroy user's session session_destroy().
the function either count number of rows fetched when select
rows matching current user, if returns 0 know row has been deleted (or never existed in first place, doesn't matter). create more sense add together active
column row, can update 0 instead of 1 if wish deactivate user, way history maintained. you'd selecting user active, i.e. 1, (0 rows returned if it's been changed 0).
do before check if users allowed see parts of website, way handled non-logged in users.
edit solution depends on how strict requirements are, if users must logged out during activity performed user need check if user still active every single time perform activity, if activity client-side need utilize ajax check if user still allowed he's do. if user given permission log-in in first place overload that's not mine tell.
edit
it doesn't matter framework you're using, okay, you're using laravel. know can utilize auth::logout()
function, utilize it! :)
function userisactive(){...} $active = userisactive(); if(!$active) { auth::logout(); }
no ajax needed unless want do javascript activity, if users can perform javascript activity requires logged-in permissions , need utilize ajax check if they're still active.
using ajax not if it's matter of security , authendication, if user turns off javascript (or has disabled reason, perhaps unknown user) you're pretty much ... i'm not going finish sentence :)
php laravel laravel-4
No comments:
Post a Comment