Get user profile & Login activity

Get user profile & Login activity

by Rajakumar Jillella -
Number of replies: 3

I'm using Moodle 3.2.


How can we get current logged in user "Login Activity", and user profile.

Ex : 

User Name : XXXX

Role : Student / Teacher / Admin

And login activity.






Average of ratings: -
In reply to Rajakumar Jillella

Re: Get user profile & Login activity

by Rajakumar Jillella -

Hi,


I have written a small code with DB tables to get login activity.

Here is my code


echo "<h3>Login Activity</h3>";

$login = mysql_query("SELECT * FROM mdl_user WHERE id=$USER->id");

while($result = mysql_fetch_array($login)){

$firstaccess = $result['firstaccess'];

$lastaccess = $result['lastaccess'];

echo "<span style='font-weight: bold;'>First access to site :</span> ".date('l,  d / M / Y', $firstaccess);

echo "<br /><span style='font-weight: bold;'>Last access to site :</span> ".date('l,  d-M-Y', $lastaccess).", ".date("G:i:s", time());

}

In reply to Rajakumar Jillella

Re: Get user profile & Login activity

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Alternatively, see if the information is already in the $USER global and save another DB call.

In reply to Gareth J Barnard

Re: Get user profile & Login activity

by Mihir J -

yes.. $USER  will always have those info you need

thanks