View Full Version : problem in get $vbulletin into external class
manuel.fho
01-14-2013, 05:27 PM
This works :D
<?php
chdir('/home/x/public_html/forum/');
require_once('./global.php');
return $vbulletin->userinfo;
This Dont Work D:
<?php
class myCMS{
function getVBInfo(){
chdir('/home/x/public_html/forum/');
require_once('./global.php');
return $vbulletin->userinfo;
}
}
$test = new myCMS();
print_r($test->getVBInfo());
Help in third party portal please.
It doesn't work because the code is written to expect some variables to be global, but if you do the include in a function, they're not. You can get around that by declaring the variables as global before you do the include. I know $vbulletin is one, I think $bootstrap is another, but unfortuantely I don't have the complete list (if you worked it out and posted it here, that would be great).
manuel.fho
01-14-2013, 05:38 PM
Sorry, this work:
global $vbulletin;
but other problem:
http://elsilencio.cl/portal/brigde.php [works]
http://www.elsilencio.cl/portal/brigde.php [dont work]
<?php
function userVB(){
$fnCwd = getcwd();
chdir('/home/x/public_html/foro/');
global $vbulletin;
include('global.php');
chdir($fnCwd);
return $vbulletin->userinfo;
}
$vb = userVB();
print_r($vb);
:-/ iam configured forum cookies to .elsilencio.cl and whitelist of redirects www.elsilencio.cl and elsilencio.cl but dont work.
http://elsilencio.cl/portal/cookies.png
forum: http://foro.elsilencio.cl/
Hmm...the only thing I can think of right now is, did you change the cookie domain setting after finding that it didn't work? You might have to clear all cookies from your browser and try again.
manuel.fho
01-14-2013, 05:46 PM
clean cookies, history, passwords, test in other browser... ff, chrome, safary, etc and same problem.
Register in forum and test the public script please.
User ID 999:
>>> console.log(document.location + ' ::: ' + document.cookie)
http://elsilencio.cl/portal/brigde.php ::: CF_ORACLE=PRECACHED; __cfduid=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaa; __utma=1915749.1000392128.1358186771.1358186771.13 58186771.1; __utmb=1915749.27.10.1358186771; __utmc=1915749; __utmz=1915749.1358186771.1.1.utmcsr=(direct)|utmc cn=(direct)|utmcmd=(none); bb_lastvisit=1358189348; bb_lastactivity=0
User ID 0:
>>> console.log(document.location + ' ::: ' + document.cookie)
http://www.elsilencio.cl/portal/brigde.php ::: __cfduid=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaa; __utma=1915749.1000392128.1358186771.1358186771.13 58186771.1; __utmb=1915749.27.10.1358186771; __utmc=1915749; __utmz=1915749.1358186771.1.1.utmcsr=(direct)|utmc cn=(direct)|utmcmd=(none); bb_lastvisit=1358189348; bb_lastactivity=0
Seems to be working for me. On either page I see:
Array ( [userid] => 17057 [temp] => [field1] => ...
if I'm logged in, and
Array ( [userid] => 0 [usergroupid] => 1 [username] => No registrado
when I log out.
manuel.fho
01-14-2013, 06:00 PM
test with www and without www logged in
test with www and without www logged in
This is what I did. But I just found out, if I choose "Guardar?" when I log in, it works. But if I don't check guardar then go to the bridge.php page, I see userid=0, and I get logged out from the site.
manuel.fho
01-14-2013, 06:06 PM
you're right.
how to fix? this is a bug in vbulletin.
--------------- Added 1358191183 at 1358191183 ---------------
my temporal solution:
$('#cb_cookieuser_navbar').hide().prop('checked', true);
All users login in with session forever.
Try adding $bootstrap to your globals, like:
global $vbulletin, $bootstrap;
include('global.php');
I don't know why that would cause this problem, but other people have asked about doing the same kind of thing and ended up needing to put in $bootstrap.
my temporal solution:
$('#cb_cookieuser_navbar').hide().prop('checked', true);
All users login in with session forever.
I guess what's happening is that access through bridge.php is causing the exitsing session to be deleted, but if you have a cookie from checking that box, then it will log you back in. I don't know why the session would end though.
manuel.fho
01-14-2013, 07:04 PM
global $vbulletin;
global $bootstrap;
not work... logged out my account :(
global $vbulletin; work only without www.
The first code you posted all works OK, right? (The one that's not in a function). Even if you don't check guardar? If that's true, then I think the problem must be that there's some variable that needs to be global.
Edit: now that I look at the code a little more, it looks like the only variables that get created in a place that assumes it's not within a function are $bootstrap and $permissions. You need "global $vbulletin" so that you can use the variable in your function, but it doesn't have to be before the include. So you can try adding $permissions to the list, but if that doesn't work, but the code works outside any function, then I'm not sure what's going on. You might have to look at the code in class_core.php that creates a session and see if you can figure out why your bridge.php script is not getting associate with the existing session (I believe it should be getting the sessionid from a cookie).
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.