Hello
I wonder if there is a way in SS to tell how long the user logged in from the front end? I will then record this and show it in the CMS backend.
thanks
Ben
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
Hello
I wonder if there is a way in SS to tell how long the user logged in from the front end? I will then record this and show it in the CMS backend.
thanks
Ben
Hi Ben,
Not something I've attempted before, but I believe you can store login attempts by using:
Security::set_login_recording(true);
Perhaps you could use this data? Something along the lines of:
$lastLoggedIn = LoginAttempt::get()->addFilter('MemberID', Member::currentUserID())->addFilter('Status', 'Success')->sort('LastUpdated DESC')->first()->LastUpdated;
Then work out the difference between that timestamp and the current time. Hope this helps
Security::set_login_recording(true);
will only make sure SS to record every login attempt. However, it will not record how long a user login for one session.
I think we need some Ajax script to 'ping' the server and tell the session is still lived and record the time in database. Then the backend will work out this recorded time and the last login attempt to tell how long the user is logged in.
but i can see there is a problem when a user logins from multiple browsers.
Hi Ben,
Yes I know that it will only record the login, not how long they're logged in for, but you can use that time as the 'start' point - i.e. when they first logged in.
If you need to record how long they're logged in for every single time they log in, that's a lot more complicated.