View Full Version : Can I insert any Vb variable in any SHTML or PHP page ?
Sharg
Wed 21st Jun '00, 10:24pm
Hi,
Can I insert any Vb variable in any SHTML or PHP page which are completely outside the Vb directories ?
lets say on my front page I want to insert the number of users, how can I do this if possible ?
Thanks,
Benj
John
Thu 22nd Jun '00, 12:07am
You would have to find the neccessary code in the vBulletin file, making sure to include any initialisation code ( eg. require("global.php"); ), and put this in your other PHP file.
John
Sharg
Thu 22nd Jun '00, 2:04am
Thanks for your answer John, how do I know in which file are each variables ?
This may sound a silly question, but I'm really new to this.
Benj
UserName
Thu 22nd Jun '00, 5:32am
If I understand the question correctly, all you need to do is query the database for any of that info. That would best be done using a .php file, but I'm pretty sure you can INCLUDE a .php file in a .shtml and have it parsed before being included.
Another option, if you don't want to bother the database with every view of the page, is to write a small script to write the variable to a text file at a certain interval (using cron) and then just INCLUDE the text file.
I'm not an expert, but that's the way that I get vB data for other pages on my site.
Sharg
Thu 22nd Jun '00, 8:24pm
Can you just give me a brutal example of the code I need to include the total member count in an external PHP file please ?
I just don't get it but this single example will light it for me.
Thanks,
Benj
Herb
Thu 22nd Jun '00, 10:11pm
<? require("global.php");
$numbersmembers=$DB_site->query_first("SELECT COUNT(userid) AS users FROM user");
$numbermembers=$numbersmembers[users]; ?>
All taken from index.php put the code somewhere at the top of the file and place the variable $numbermembers wherever you want it displayed on the external page..
[Edited by Herb on 06-23-2000 at 09:14 AM]
Sharg
Sat 24th Jun '00, 12:30am
Well, i've created a test.php page in the same directory than global.php, I've put your code on top, but after, when I put
$numbersmembers
in the page and then load the page, it just show "$numbersmembers" printed ?!
Benj
[Edited by Benj on 06-24-2000 at 11:32 AM]
UserName
Sat 24th Jun '00, 7:43am
You need to make sure that the variable that you want to display the value of is inside of a PHP tag. For example, if you are using a .php file, and you have included the code that Herb suggested, you should be able to simply put:
<?PHP echo "$numbermembers"; ?>
If you need to use a .shtml file, I think that you might be able to do something like this:
Put the code that Herb suggested, followed by the echo command above into a .php file with no html and save it as something like number_members.php. Then, where you need to print the variable, simply include the nember_members.php file using a virtual include:
<!--#include virtual="number_members.php" -->
The server should, I believe, parse the .php file and simply return the output of the variable. I have not tried this, but it seems to me that it would work.
Before I found PHP I used to use XSSI (http://hotwired.lycos.com/webmonkey/97/39/index1a.html?tw=backend) to make some variables available throughout certain documents. I'm not sure if including PHP files works in exactly the same way but it seems very similar...
Sharg
Sat 24th Jun '00, 8:16am
I can use PHP :)
And it worked :)
Now how can I do the same thing with a file OUTSIDE the /vbscript directory ?
When I put the unix full path (<? require("/big/dom/domain/www/vbscript/global.php");
It returns error message....
Fatal error: Failed opening required 'admin/config.php' in /domain/www/vbscript/global.php on line 31
How could I specify a valid path ?
Thanks,
Benj
[Edited by Benj on 06-24-2000 at 07:20 PM]
Sharg
Sun 25th Jun '00, 7:20am
C'mon guys, i'm just close to be able to do what I want...
UserName
Sun 25th Jun '00, 8:04am
Hi Benj -
I tried to wait for one of the gurus to respond, but they haven't, so I will. Here is a really lame idea that might solve the problem, though I doubt it's the best method:
Just change line 31 in Global.php from:
require("admin/config.php");
to:
require("/big/dom/domain/www/vbscript/admin/config.php");
The absolute path instead of the relative one.
You may run into other required files that it cannot find, but I think this would take care of the immediate problem.
Remember, I'm just learning PHP/MySQL, so my advice may need some fine tuning...
<-- Edited message to fix Line # -->
[Edited by UserName on 06-25-2000 at 07:05 PM]
Sharg
Sun 25th Jun '00, 7:24pm
:)
It worked ;)
Thanks a lot !
I'm gonna have lots of fun with this ;)
Also, do you know how to know which lines of codes to add for a given require function ? For example, to add the total posts, what should I require, and how should I add it to the require lines I already have and so on ?
Thanks,
Benj
John
Tue 4th Jul '00, 7:53am
The best way to do this would probably be to use the chdir() php function:
chdir("/big/dom/domain/www/vbscript");
require("global.php");
That would be put in your own php script wherever you want it on your server.
John
Sharg
Wed 26th Jul '00, 10:20am
Hi,
I have implemeted this, but got this error message on the very top of my page:
Warning: Oops, php3_SetCookie called after header has been sent in /xpk_hq/www/community/global.php on line 712
Only non registered member get this, not registered, as if it tries to find a cookies where it can't (for non registered of course).
I really need a fix, thanks
Benj
vBulletin® v3.8.0 Beta 4, Copyright ©2000-2008, Jelsoft Enterprises Ltd.