Register Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools
  #1  
Old 10 Dec 2015, 12:40
InPhaseVB InPhaseVB is offline
 
Join Date: Dec 2015
Check if logged in PHP script

vBulletin 5.1.9

Hello I have a number of external pages written in PHP that need to check that a user is logged into vBulletin to allow access to these pages. After much searching I have a script that can check if the user has vb cookies but it is not always the case that cookies are placed on the browser when logged in.

/*--------- PHP Code ---------*/
$vbpath = '/home/ourperfo/public_html';

define('CSRF_PROTECTION', false);
require_once($vbpath . '/includes/vb5/autoloader.php');
error_reporting(E_ALL);
vB5_Autoloader::register($vbpath);
vB5_Frontend_Application::init('config.php');
$userid = vB5_Cookie::get('userid', vB5_Cookie::TYPE_UINT);
$hash = vB5_Cookie::get('password', vB5_Cookie::TYPE_STRING);

if ($userid > 0 AND !empty($hash))
{
echo "logged in";
}
else
{
echo "NOT logged in";
}
/*--------- PHP Code END ---------*/

So what I was wondering if there was a script to check if a user is logged in on the browser I could use. Thanks.
Reply With Quote
  #2  
Old 10 Dec 2015, 22:38
Replicant's Avatar
Replicant Replicant is offline
 
Join Date: Sep 2014
Real name: Mel
The userid and password cookies are not set when one logs in if they haven't clicked the remember me button. So, using the script you have above, if the cookie check fails, then provide a login prompt. I'm assuming this script is based on David Groves' external login tutorial so that part should be trivial. Remove the remember me option and hardcode remember in the login script. This will force the cookies to be set and you will be off and running.
__________________
VB5 mods - RepliClock VB4 mods - Member Online Status
Reply With Quote
  #3  
Old 23 Jan 2016, 18:04
ChristianAlfred ChristianAlfred is offline
 
Join Date: Nov 2007
This was great. If you could extract username it would be nice.
Reply With Quote
  #4  
Old 23 Jan 2016, 20:21
Replicant's Avatar
Replicant Replicant is offline
 
Join Date: Sep 2014
Real name: Mel
You can use this in the php code if you have already determined the userid in your script which only returns a username.

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Or, you can use if you don't which returns a fairly large array with tons of user info.

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Either of these can also be called via AJAX in javascript so it can also it can be implemented on cloud also.
[forum root]/ajax/api/user/fetchUserName?userid=3 using pageData['userid'] to get the userid
[forum root]/ajax/api/user/fetchUserinfo if you want more data than just a user name.
__________________
VB5 mods - RepliClock VB4 mods - Member Online Status
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


New To Site? Need Help?

All times are GMT. The time now is 16:50.

Layout Options | Width: Wide Color: