View Full Version : Show external page only if logged in
kklimack
06-03-2013, 05:23 PM
Hello, I already have external pages on a website and am looking to only show the pages if the user is logged into their vBulletin account on the same website. I am unsure what to include in PHP from vbulletin to make this happen.
Basically... if user is logged in then show page. If not, return to the standard vBulletin login form (/forum/login.php?do=login).
Any help would be appreciated!
Zachery
06-03-2013, 07:55 PM
You should really check out some of the articles for building your own vBulletin powered pages.
kklimack
06-06-2013, 12:32 PM
Sorry, this is a separate little app that has already been written. There is many pages and PHP functions. I really just need to know what string I would use to check if the user is logged on or not.
Are you already including vbulletin's global.php in your external pages? If so, you just need to check for $vbulletin->userinfo['userid'] != 0, which will only be true for logged in users.
If you're not including global.php, you need to do that. The "current working directory" needs to be your forum directory (the directory that has global.php) for the include to work. So if that isn't where your external script is located, you would need to chdir() to it before the include and maybe chdir() back to the original directory if other things in your script depend on it.
Also, if your external script isn't in the vb forum directory, then for that to work your vbulletin cookie path needs to be set '/' (which I believe is the default), otherwise the vb cookies won't be sent and users won't appear logged in.
To be honest I think including global.php does more than you need to do just to check if the user is logged in. I think I remember reading a thread where someone had managed to include the file includes/init.php, which will do less unnecessary work, but I can't remember what needs to be done for that to work.
kklimack
06-06-2013, 01:14 PM
I figured it out. Here is the code I use if anyone else needs it.
<?php
$root_path = $_SERVER['DOCUMENT_ROOT'];
chdir($root_path."/forum/");
require($root_path."/forum/global.php");
require_once($root_path."/forum/includes/functions_login.php");
$username = $vbulletin->userinfo['username'];
$userid = $vbulletin->userinfo['userid'];
if ($userid !=0)
{
echo "Hello $username";
}
else {
echo "No account logged in";
}
?>
--------------- Added 1370528102 at 1370528102 ---------------
Thanks KH99!
vBulletin® v3.8.12 by vBS, Copyright ©2000-2024, vBulletin Solutions Inc.