vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   problem in get $vbulletin into external class (https://vborg.vbsupport.ru/showthread.php?t=293925)

manuel.fho 01-14-2013 05:27 PM

problem in get $vbulletin into external class
 
This works :D
PHP Code:

<?php
chdir
('/home/x/public_html/forum/');
require_once(
'./global.php');
return 
$vbulletin->userinfo;

This Dont Work D:
PHP Code:

<?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.

kh99 01-14-2013 05:32 PM

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 Code:

<?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/

kh99 01-14-2013 05:45 PM

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

kh99 01-14-2013 05:54 PM

Seems to be working for me. On either page I see:
Code:

Array ( [userid] => 17057 [temp] => [field1] => ...

if I'm logged in, and
Code:

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

kh99 01-14-2013 06:03 PM

Quote:

Originally Posted by manuel.fho (Post 2396837)
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 [DATE]1358191183[/DATE] at [TIME]1358191183[/TIME] ---------------

my temporal solution:
Code:

$('#cb_cookieuser_navbar').hide().prop('checked', true);
All users login in with session forever.

kh99 01-14-2013 06:20 PM

Try adding $bootstrap to your globals, like:
Code:

    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.

kh99 01-14-2013 06:22 PM

Quote:

Originally Posted by manuel.fho (Post 2396840)
my temporal solution:
Code:

$('#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.

kh99 01-14-2013 07:59 PM

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).


All times are GMT. The time now is 03:41 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01210 seconds
  • Memory Usage 1,754KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (5)bbcode_code_printable
  • (3)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (13)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete