Try the beta version of the new SilverStripe documentation

For the next 2 weeks you can use the new documentation website and give us your feedback.


This document contains information about a future release and not the current stable version (3.1).

Be aware that information on this page may change and API's may not be stable for production use.

Howto: Track Member Logins

Sometimes its good to know how active your users are, and when they last visited the site (and logged on). A simple LastVisited property on the Member record with some hooks into the login process can achieve this. In addition, a NumVisit property will tell us how often the member has visited. Or more specifically, how often he has started a browser session, either through explicitly logging in or by invoking the "remember me" functionality.

class MyMemberExtension extends DataExtension {
    private static $db = array(
        'LastVisited' => 'Datetime',
        'NumVisit' => 'Int',
    public function memberLoggedIn() {
    public function memberAutoLoggedIn() {
    public function updateCMSFields(FieldList $fields) {
        $fields->addFieldsToTab('Root.Main', array(
            ReadonlyField::create('LastVisited', 'Last visited'),
            ReadonlyField::create('NumVisits', 'Number of visits')
    protected function logVisit() {
        if(!Security::database_is_ready()) return;
            'UPDATE "Member" SET "LastVisited" = %s, "NumVisit" = "NumVisit" + 1 WHERE "ID" = %d',

Now you just need to apply this extension through your config:

        - MyMemberExtension


Comment policy: Please use comments for tips and corrections about the described functionality.
Comments are moderated, we reserve the right to remove comments that are inappropriate or are no longer relevant. Use the Silverstripe Forum to ask questions.

blog comments powered by Disqus