MyBB Community Forums

Full Version: Where to hook user login?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
With what hook can I get any log in? With any I mean including the log in of users that are already logged in and return to the site.
I'm not completely sure what you mean, but try datahandler_login_complete_end: https://github.com/mybb/mybb/blob/featur...n.php#L310 (or _start)
Thanks for helping Destroy666

I'm trying to hook the user log in to detect multiple accounts accessing from the same IP.
I've just tried to hook with a a simple echo statement to see what hook was being called:
datahandler_login_complete_end (and _start) and it's not being called
datahandler_login_validate_start/end aren't eihter
member_do_login_start and member_do_login_end are, but user->uid isn't set.
Are you using 1.6 or 1.8? This info should be included if it's not the latest 1.8.4 version. Otherwise login datahandler hooks should work fine and you can access UID with $this->login_data['uid']: https://github.com/mybb/mybb/blob/featur...n.php#L238 (where $this is the passed hook parameter)

In 1.6 you can use member_do_login_end as you said: https://github.com/mybb/mybb/blob/master....php#L1277 UID is in $user['uid']: https://github.com/mybb/mybb/blob/master....php#L1260 (don't forget to globalize $user in your function).
I'll check it when I have some spare time. Thank you.
(2015-04-29, 03:56 PM)Destroy666 Wrote: [ -> ]Are you using 1.6 or 1.8? This info should be included if it's not the latest 1.8.4 version. Otherwise login datahandler hooks should work fine and you can access UID with $this->login_data['uid']: https://github.com/mybb/mybb/blob/featur...n.php#L238 (where $this is the passed hook parameter)

In 1.6 you can use member_do_login_end as you said: https://github.com/mybb/mybb/blob/master....php#L1277 UID is in $user['uid']: https://github.com/mybb/mybb/blob/master....php#L1260 (don't forget to globalize $user in your function).

That didn't work for me. Just getting a blank page. Any idea what am I missing?

$plugins->add_hook('datahandler_login_complete_start', 'last');

function last()
{
	global $plugins, $db, $mybb, $session;
	
	$test = $this->login_data['uid'];

			echo '<script> alert("'.$test.'")</script>';

}
You can't use $this outside of a class.
(2015-12-01, 09:41 AM)StefanT Wrote: [ -> ]You can't use $this outside of a class.

I thought that didn't matter because I hooked my function to it.
Got it working, cheers.