PDA

View Full Version : How to get current user thier ID?


M4GN3T
08-10-2011, 10:35 PM
Hi Guys,

First time developing a plugin for vBulletin, and i think im about to pass out xD. I'm trying to do the following:

$userid = $vbulletin->userinfo[userid];
$sql="SELECT `xp` FROM `rank` WHERE `userid` = '".$userid."'";

To succesfully run this query, i need the current, logged in, user thier user ID. The docs tell me to use userinfo[userid] but its not working for me. Am i doing something wrong? If so, what is it?

kh99
08-10-2011, 10:43 PM
$vbulletin->userinfo[userid] should work. Depending on what hook location you're using, you may need "global $vbulletin'" at the beginning of your code.

M4GN3T
08-10-2011, 10:46 PM
$vbulletin->userinfo[userid] should work. Depending on what hook location you're using, you may need "global $vbulletin'" at the beginning of your code.

I am using init_startup, putting a Global didn't work.

kh99
08-10-2011, 10:51 PM
Oh, that's why - init_startup is too early. Maybe try global_bootstrap_init_start.

M4GN3T
08-10-2011, 10:56 PM
Oh, that's why - init_startup is too early. Maybe try global_bootstrap_init_start.

And ur right again, thanks man. i should hire you =p haha.

Jhonnyf
08-10-2011, 11:02 PM
try adding global $vbulletin; as first line

M4GN3T
08-10-2011, 11:36 PM
What is the variable to get the User ID of the currently showing MEMBERINFO (users profile ID)? Can't seem to find it.

EDIT: Got it, $vbulletin->GPC['userid'];

Thanks guys =D!