View Full Version : getting userid on custom page
squishi
11-29-2010, 08:48 PM
On a custom page that is called periodically with ajax, I would like to check the userid of the user. (I want to compare it with a variable to show a ban button in my chat application).
So this is what I have:
chdir('../../forum');
require_once('./global.php');
echo "vbuserinfo: ".$vbulletin->userinfo['userid'];
die();
But vbulletin-userinfo['userid'] is zero ("vbuserinfo: 0").
I am logged in at the forum and global.php is found. I don't understand why it's not working. :confused:
Simon Lloyd
11-30-2010, 04:26 AM
You probably need to use this $bbuserinfo[userid]
squishi
11-30-2010, 07:48 AM
In a php script? The above code is not in a template.
Lynne
11-30-2010, 02:27 PM
My guess would be that global.php is actually not being called. You say you know it's being called - how do you know that?
In ths thread: https://vborg.vbsupport.ru/showthread.php?t=254375 I notice that your $_REQUEST doesn't contain any cookies. To be honest I'm not 100% sure that it should, but the docs say it should. So maybe somehow the cookies aren't being sent with your request and so you're not seen as logged in?
squishi
11-30-2010, 11:45 PM
My guess would be that global.php is actually not being called. You say you know it's being called - how do you know that?
1) The page would show an error message if the file was not found.
2) Vbulletin->userinfo['userid'] is set to 0. I did not set it to zero, so global.php must have set it.
--------------- Added 1291168079 at 1291168079 ---------------
So maybe somehow the cookies aren't being sent with your request and so you're not seen as logged in?
How would I make the ajax call submit the cookies then? :confused:
Unfortunately I don't know. I always thought they got included automagically based on the domain name you are sending the request to.
Anyone else know?
vvvv Lynne has a good idea.
Lynne
12-01-2010, 01:17 AM
Is this in the middle of a function - perhaps you need to make $vbulletin global?
(You wouldn't see errors if you don't have reporting on, so you may want to check your error_logs just in case.)
squishi
12-01-2010, 05:55 PM
It's not in a function. I would have received a warning if global was not found.
And the code that I posted above appears exactly the way I posted it. It should work in a function.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.