PDA

View Full Version : Passing PHP variables between products


swissbob
02-11-2007, 10:55 PM
I have a php product hooked to global_start which adds in a banner add at the top of every page, and also does some basic geo-location and provides a country code. Obviously this requires a database access.

I want to be able to pass the same country code on to another product that shows another banner on the threads page (below the first post). This has to be hooked to the postbit_display_start to get it to work I think.

The question is - how do I store a global variable accessible in the second script please? I can't find anything about this through searching.

Analogpoint
02-12-2007, 01:16 AM
When you set a variable in the first plugin, it may or may not be in the global scope. It will be in whatever scope the hook function is called from. To do what you want to do, simply save the variable in the super global array.

$GLOBALS['testvar'] = 'testval';

It will be available for the rest of the script (unless someone unsets it along the way :))

swissbob
02-12-2007, 01:36 AM
That worked perfectly, thank you. You have saved me a good few hours of trawling and desperate trial and error coding. Much appreciated.

Analogpoint
02-12-2007, 01:39 AM
No problem, just realise that it's a hack and not "clean", since the variable is not encased in a class/object with access limitations etc, it's "out in the open" and can be modified/deleted by any other plugin you might install.

AN-net
02-13-2007, 12:18 PM
so make sure you sanatize that variable before hand. you could also add it to the $vbulletin variable which is usually available to all parts of vBulletin.