Create a log of member logins?

Is there a way to generate a log of member logins? i am just looking for something basic. Who logged in and when.

Re: [zip222] Create a log of member logins?

By Jason - September 10, 2010

Hi,

If you're using the website Membership Plugin, you could add some code to the login function that writes a record to a table or to a file.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Create a log of member logins?

I wouldn't know how to do this myself, but could do it with some guidance or through priority consulting. I need to get an estimate to my client sometime on Monday for this work. should I submit a priority consulting request?

Re: [zip222] Create a log of member logins?

By Chris - September 12, 2010

Hi zip222,

Maybe I can help without sending you to consulting. If this doesn't work for you, please send in a request for a quote and we'll be happy to get back to you as soon as possible.

Create a Multi Record section called "Login Log". Modify it and remove all the fields except "num" and "createdDate" (note that you'll need to "Enable System Field Editing" under the "Advanced Commands..." dropdown to remove some of the fields.) Add a List Field called "Who". Modify your "Who" field as follows:

List Options: Get options from database (advanced)

Section Tablename: accounts
Use this field for option values: num
Use this field for option labels: username


Now, make some more changes to your Login Log section, this time at the top of the page:

In the General tab, change "ListPage Fields" to "createdDate, who". Under the Viewer Urls tab, change "Filename Fields" to "". Under the Searching tab, set "Search Fields" to "who, createdDate". Finally, under the Sorting tab, set "Order By" to "createdDate DESC". Now click Save Details.

Now open up cmsAdmin/plugins/websiteMembership/websiteMembership.php in a text editor and find "redirect on success". Add the code in red before "redirect on success":

// CUSTOM CODE! add record to login_log
global $TABLE_PREFIX;
mysql_query(mysql_escapef("INSERT INTO {$TABLE_PREFIX}login_log SET createdDate = NOW(), who = ?", $CURRENT_USER['num']))
or die("Mysql error adding login_log record: ". htmlspecialchars(mysql_error()) . "\n");


// redirect on success


I hope this helps! Please let me know if you have any questions.
All the best,
Chris

Re: [chris] Create a log of member logins?

That's awesome! Works perfectly.

Slightly related question:
In your instructions you specify that the membership plugin is inside of a folder called "websiteMembership/" - is it a problem if my is not? The php file is just placed in the plugins folder.