Register Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools
  #1  
Old 02 Oct 2011, 08:57
MoMan MoMan is offline
 
Join Date: Oct 2005
Integrating external script with vB

Hi,

I currently integrate my homepage with vbulletin in order to fetch user login and session data. The code I use to do that is as follows:


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

...and it works like a charm. However, when I wrap that in a function, like so:


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

Everything mysteriously blows up and I get the following PHP error:

PHP Fatal error: Call to a member function query_first_slave() on a non-object in [DIR]/forums/includes/functions.php on line 1386

Where line 1386 uses $vbulletin->db->query_first_slave to fetch the userinfo.

Any ideas why this could be? Is it a scope issue?

As a temporary workaround, I've simply placed the code in a separate file and include it whenever I need the integration. I know that a better solution would be to connect to the database only to fetch user data and use my own session, but for now I want to keep things quick and dirty (and secure)
__________________
Adam

Admin of PentaxForums.com - Big-Board
Reply With Quote
  #2  
Old 02 Oct 2011, 10:47
kh99 kh99 is offline
 
Join Date: Aug 2009
Real name: Kevin
Yes, I think it's a scope issue. The vb code is intending to create some global variables but when you put the "require" in a function they're not global.

Edit: maybe if you could figure out which variables those are you could add "global" statements in your function before the require_once('global.php').

Last edited by kh99; 02 Oct 2011 at 11:37.
Reply With Quote
  #3  
Old 02 Oct 2011, 18:49
MoMan MoMan is offline
 
Join Date: Oct 2005
Though so - but I can't explain it! I tried making everything that ended up in $GLOBALS after the first code ran global inside the function, but that didn't help either (there were dozens of variables!).

Thanks for the reply- I suppose that instead of calling a function I will just include the code from a while while I'm in the global scope.
__________________
Adam

Admin of PentaxForums.com - Big-Board
Reply With Quote
  #4  
Old 03 Oct 2011, 01:07
kh99 kh99 is offline
 
Join Date: Aug 2009
Real name: Kevin
Hmm...I was curious about this (I'm not really any kind of php expert so I like to figure these things out). I found that if I just put a "global $vbulletin;" at the beginning of the login function it seems to work OK. I guess most of the globals aren't used for what you're doing (unless maybe it's because I don't have all you code? Anyway, the error you posted above goes away).
Reply With Quote
  #5  
Old 04 Oct 2011, 03:57
MoMan MoMan is offline
 
Join Date: Oct 2005
Let me try again- I could have sworn I tried that, though!

Also, if you want to use functions as if they were in the global scope, here's a nice line of code that does just that (I use it for template evaluations so you don't have to write out the eval() statement every time:


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

--------------- Added 04 Oct 2011 at 04:00 ---------------

Update: no dice. Maybe my version to PHP is to blame (5.1.6)? Highly unlikely, but possible, I guess. I don't see reason from a coding standpoint that the inclusion from inside the function should work, as even with the variable scope vbulletin shouldn't care.
__________________
Adam

Admin of PentaxForums.com - Big-Board
Reply With Quote
  #6  
Old 04 Oct 2011, 10:29
kh99 kh99 is offline
 
Join Date: Aug 2009
Real name: Kevin
The extract thing is pretty handy, but of course it will only import the global variables that exist already - variables that are created after that line won't automatically be global, of course. And $vbulletin doesn't exist before global.php is included.
Reply With Quote
  #7  
Old 06 Oct 2011, 09:05
souperman souperman is offline
 
Join Date: Mar 2011
I can tell you that it's not your php version. I had a similar problem with php 5.2.17, I fixed it by creating by own global file :P

Either way it's probably a scope issue like kh99 mentioned.
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
Forum Jump


New To Site? Need Help?

All times are GMT. The time now is 13:33.

Layout Options | Width: Wide Color: