Cannot grab correct UID from hook - Printable Version +- MyBB Community Forums (https://community.mybb.com) +-- Forum: Extensions (https://community.mybb.com/forum-201.html) +--- Forum: Plugins (https://community.mybb.com/forum-73.html) +---- Forum: Plugin Development (https://community.mybb.com/forum-68.html) +---- Thread: Cannot grab correct UID from hook (/thread-180667.html) |
Cannot grab correct UID from hook - Dexie - 2015-09-23 I am trying to write a plugin that will set an identical session cookie for another area of my website after a successful MyBB login. Everything works exactly how I want, except it will not grab the correct UID from the session; instead it is returning "0". Here is the relevant section of my plugin code:
The result creates a cookie called "my_session" with the following value: 0+ABCDE+2b9463c2ea380080735787d18af3c1db I have been able to confirm that $sessionid is correct with each login, but instead of "1" (which is my UID), it keeps grabbing "0". This is really bizarre because when I check the database, the session value is a match for my UID (1). There are no sessions logged for UID "0" because you must be logged-in to view the page. Any help would be appreciated! RE: Cannot grab correct UID from hook - SvePu - 2015-09-24 Did you tried:
RE: Cannot grab correct UID from hook - Dexie - 2015-09-24 (2015-09-24, 10:01 AM)SvePu Wrote: Did you tried: Yes. With quotes, without quotes and with only $myuser. $sessionid is correct, but $myuser is always set to 0. For some reason the $myuser variable is not passing from MyBB to my plugin. Am I using the wrong hook? RE: Cannot grab correct UID from hook - RateU - 2015-09-24 Try using $GLOBALS['user']['uid'] RE: Cannot grab correct UID from hook - Dexie - 2015-09-24 (2015-09-24, 08:53 PM)RateU Wrote: Try using $GLOBALS['user']['uid'] I tried this:
Unfortunately, I still do not get any value for UID. Did I do something wrong? I was able to circumvent the issue by adding this line of code to inc/datahandlers/login.php right after MyBB sets the "mybbuser" cookie.
I really did not want to do it that way, but until I can get the UID variable passed to my plugin, I do not know of any other solution. It is strange that $SID is being passed, but not $UID. (Oh, and I tried using the "my_setcookie" function in my plugin just for kicks, but that did not manage to pull $UID either). RE: Cannot grab correct UID from hook - RateU - 2015-09-25 What I meant is replace $mybb->user['uid'] to $GLOBALS['user']['uid'] RE: Cannot grab correct UID from hook - Shade - 2015-09-25 If you are hooking into datahandler_login_complete_end, the $mybb->user object is still stuck to a general guest data. The user data will be loaded afterwards, so you should grab the authenticated user data by using the argument passed in the hook, which is a "by-reference" hook type:
|