Hi I am implementing a chat/inbox feature on my website. When users are not logged in and receive a message from another user, the website will send an email to the recipient of the message. However when the user is logged in it won't.
My questions is how do I tell whether a user is logged in or not? For example, if a user is logged in and then closes the browser my backend wouldn't know anything.
Btw I'm building a Angularjs SPA with a restful API in Laravel 4.?
if you are using build-in Laravel Auth:
if(Auth::check())
{
//do something
}
if you are using Sentry:
if(Sentry::check())
{
//do something
}
I suggest using Ajax to ping the DB when the user is logged in. Add a last_logged_in
column of type Date
So when the users are logging in they update their last_logged_in
field to the current date. You can do this Ajax as often as you like (very minimal performance issues). To see if a user is logged in simply check the last_logged_in
date and compare it to the current date minus some time (1 minutes)..
I would not suggest using it to email users because it may result in lots of spam. You can use the is_logged_in
field in addition but don't use it on it's own.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.