PDA

View Full Version : How Do I Use SSI/Includes in my forums?


JamesUS
Sat 13th Oct '01, 7:16am
To use Includes in your forums, you need to add this to your 'phpinclude' template:


ob_start();
require("/path/to/include/file");
$file = ob_get_contents();
ob_end_clean();


Replace '/path/to/include/file' with the path to the file you want to include.
Then put '$file' in the templates where you want your included file to display.

eva2000
Sat 13th Oct '01, 9:00am
Just a question that others and I may ask, what if you want to include more than 1 file i.e. $file1 and $file2 ?

JamesUS
Sat 13th Oct '01, 9:23am
Good question :) To include more than one file, just repeat my code above as many times as you need to, changing the '$file' variable to something different each time.

ne00
Mon 15th Oct '01, 2:51pm
How would you use ssi for php3?

This bit of code is for php4 only since when I try it out I get the error message Parse error: parse error in ./global.php on line 316.

Raz Meister
Mon 15th Oct '01, 7:10pm
To do SSI use the funtion virtual(...)virtual("/path/to/include/file");

JamesUS
Tue 16th Oct '01, 3:23am
That shouldn't work actually...it will possibly break other things.

If you're using PHP3, then you have to modify the code directly as the phpinclude template can't do php3 includes.

Raz Meister
Tue 16th Oct '01, 7:47am
Yes it seems there are quite a few bugs with the "virtual" function. One is that it will change the current directory to the file that you just included.

A workaround for that (suggested here (http://www.php.net/manual/en/function.virtual.php)) is:A workaround is:
$curDir = dirname( getenv( "SCRIPT_FILENAME" ) );
virtual ( "/someotherdir/file.shtml" );
chdir( $curDir );

Unknown553
Wed 31st Oct '01, 11:04pm
Originally posted by JamesUS
To use Includes in your forums, you need to add this to your 'phpinclude' template:


ob_start();
require("/path/to/include/file");
$file = ob_get_contents();
ob_end_clean();


Replace '/path/to/include/file' with the path to the file you want to include.
Then put '$file' in the templates where you want your included file to display.
This doesn't seem to work with executable files (cgi, perl). Know how to include those??

ja5es
Mon 19th Nov '01, 6:14pm
try this:

ob_start();
include("/path/to/include/file");
$file = ob_get_contents();
ob_end_clean();

The "include()" funtion will run most kinds of scripts, .txt, php, cgi (I think), etc.

ibeblunt
Thu 20th Dec '01, 6:53pm
In my phpinclude template I have the following:

ob_start();
require("/home/fpalmer/web/html/templates/sitewide/inc_daily_news.html");
$sidebar_daily_news = ob_get_contents();
ob_end_clean();

ob_start();
require("/home/fpalmer/web/html/templates/sitewide/inc_forum_sidebar_features.html");
$sidebar_features = ob_get_contents();
ob_end_clean();

ob_start();
require("/home/fpalmer/web/html/templates/sitewide/inc__forum_sidebar_shop.html");
$sidebar_shop = ob_get_contents();
ob_end_clean();

In my forumhome, I have the following:

$sidebar_shop<br>$sidebar_daily_news<br>$sidebar_features

And here is the end result:
http://www.sohh.com/forums/index.php

Visionray
Wed 20th Feb '02, 5:09am
hey thanks james b! That script worked great for a banner rotation php file :D

SunTanning.com
Mon 4th Mar '02, 1:55pm
Where is this phpinclude template that can be edited to allow cgi scripts to be called from within the forum?

I want to call a banner program using SSI call but cannot get that to work in vBulletin like it did in ubb.

memobug
Thu 1st Aug '02, 6:29pm
Originally posted by SunTanning.com
Where is this phpinclude template that can be edited to allow cgi scripts to be called from within the forum?

I want to call a banner program using SSI call but cannot get that to work in vBulletin like it did in ubb.

Go into Admin mode and look down on the left towards the bottom select Edit Templates and click EXPAND in the main window. THe php-include template will be down towards the bottom.

Regards,

Matt

memobug
Thu 1st Aug '02, 6:33pm
How can I pass a variable as a command line arguments from vBulletin into the included script?

Example, I have written a php program for photopost that will display a few of a user's thumbs. I'd like to put that into the profile. The script accepts a userid as a commandline argument, for example user #26 is

e.g. showthumbs.php?userid=26

Can I just replace 26 with the variable I want passed?

Thanks,

Matt

numerodix
Thu 1st Aug '02, 11:39pm
EDIT:

I had problems getting a php script to execute but I finally got it working. For anyone interested, this is probably not the best solution but it works for me...

ob_start();
chdir("/path/to/script");
require("script.php");
chdir("/path/to/forum");
$execute_script = ob_get_contents();
ob_end_clean();

GuruXL
Thu 22nd Aug '02, 8:29pm
This code doesn't work:


ob_start();
require("/path/to/include/file");
$file = ob_get_contents();
ob_end_clean();


Everytime, I include it, i get my Template Driven page blank...i am UPSET!!!

I am desparate here, I need HELP!!! Anybody!!! Help!!! I need somebody!!! Help!!!!

grandma
Sat 21st Sep '02, 10:28am
If your using numerodi's code

ob_start();
chdir("/path/to/script");
require("script.php");
chdir("/path/to/forum");
$execute_script = ob_get_contents();
ob_end_clean();


1) Double check your paths to the script and forum
2) In the template your using, call the script by using $execute_script.

The first time, I got the blank screen as well, until I did the above 2 things.

Grandma

Dark Eternal
Thu 26th Sep '02, 11:38pm
Perhaps I'm doing something wrong. I have tried adding all the various codes to my phpinclude template and then adding the $file variable to the template I wish my banner rotation script to come up. I can make the paths appear as for example "/home/public_html/banner.php" or "http://www.hmas.org/banner.php" and the area where the banners should appear come up blank.

Also in the phpincludes template the code must include two slashes in front of it or I get parse errors or database errors.

For example

// ob_start();
// require("/banner.php");
// $banner = ob_get_contents();
// ob_end_clean();

I will admit flat out I am a true php dummy, so perhaps I'm doing something wrong. But I figured I'd try, because it seems to be working for everyone esle but me :confused:

grandma
Fri 27th Sep '02, 8:31am
Well, I'm far from a PHP person, but I can tell ya the only reason it's working with the two slashes (//) in front of them is because it's being commented out. You can put anything after the slashes and it will work just fine.

How about posting your code in the PHPINCLUDE template? (Minus the paths) Your probably missing a semicolon, or have some other "syntax" error.

Grandma

Dark Eternal
Fri 27th Sep '02, 9:10pm
Thanks for the quick reply. This is everything that is in the phpinclude template exactly as is (including the code I found in this thread. I never alterd it before now).

// This code is PHP4 only:
// ob_start();
// require("yourheader.html");
// $header = ob_get_contents();
// ob_end_clean();
// ob_start();
// require("/path/to/banner.php");
// $banner = ob_get_contents();
// ob_end_clean();

I did find a work around, if I can't get it to work via an include, i'll just use a 468 x 60 IFrame. 98% of my traffic is IE or NS 6.0 anyway.

Thanks, again!

grandma
Fri 27th Sep '02, 10:34pm
How about this....

ob_start();
chdir("/path/to/BANNER_SCRIPT");
require("BANNER_SCRIPT_NAME.php");
chdir("/path/to/YOUR_FORUM);
$execute_script = ob_get_contents();
ob_end_clean();

And in the displayforum template, include the variable.

$execute_script

Good luck!

BTW, wheredid you get the little fancy script that shows the posts and # of view on your homepage? It looks great.

Grandma

Dark Eternal
Wed 2nd Oct '02, 2:53am
I found those at vBulletin.org the script is called "Last X Posts"

The thread should still be here...
http://www.vbulletin.com/forum/showthread.php?threadid=12324

Hope that helps!

Cygnus
Mon 30th Dec '02, 8:14pm
Thanks Grandma! That code worked perfectly for me.

Cygnus

mackers8923
Mon 27th Jan '03, 10:09pm
Hey guys


//CHAT BANNER

$chatters=$DB_site->query_first("SELECT count(*) as results from session where lastactivity>$datecut AND location=concat('/forums/main_chat.php?s=',sessionhash)");

if ($chatters[results]!=0) {

$chatonoff="on.gif";

} else {

$chatonoff="off.gif";

}

eval("\$chatdisplay = \"".gettemplate('chatdisplay')."\";");

//CHAT BANNER END



I am really suffering with this one at the minute, I am trying to get $chatters to come up on my postbit area. I have the Chat User's: coming up fine but I can't get the result to work even though it works on my forum home page. Any Idea's?

SNOWCRAZE
Wed 5th Feb '03, 11:54am
Hi, i been search and struggle w/ that phpinclude... what i did put code to:ob_start();
require("frontphoto.php" );
$photo_script = ob_get_contents();
ob_end_clean()

and i get parse error in snowcraze.com/board/global.php(313): eval()'d code on line 12. What it suppose means? I can't get thing work on phpinclude...

also i did try:
require("/home/snowcraze.com/frontphoto.php");
and
require("/home/snowcraze.com/board/frontphoto.php");

and I get complete blank page on message board..

SNOWCRAZE
Wed 5th Feb '03, 6:08pm
and i get parse error in snowcraze.com/board/global.php(313): eval()'d code on line 12. What it suppose means? I can't get thing work on phpinclude...


I check on global.php line 313:
eval(gettemplate('phpinclude',0,0));
is that correct? or change from 0 to 1? Im not really php whiz this one...

GoTTi
Wed 2nd Apr '03, 3:39am
any1 get this working yet or know how to work cgi with the forum?

squall14716
Wed 2nd Apr '03, 6:39pm
It means there is a parse error inside the phpinclude template.

memobug
Thu 26th Jun '03, 6:36pm
I'd still like to be able to pass a vbulletin variable to the script I am calling.. I have no problem getting it to execute, while

showthumbs.php?userid=26

works great on the command line, but from a template I always get the same userid (0) being sent when I plug in a vBulletin parameter in place of 26.

Regards,

Matt

karmanis
Fri 25th Jul '03, 11:19pm
Lets say that I include several files (more than 30) in my phpincludes template... does this add queries or other weight on my vb pages even if I would not eventually call the files to be shown in a vb page ?

I ask this because I observed that an error occurs when I add an include that conflicts with another, in phpincludes, and this error continues to occur even if I will not call the files from my templates.

so, should I suppose that the "included" files are parsed anyway and add load to my vb pages even if I don't call them ???

thanks
:)

Noiz Pollution
Sun 3rd Aug '03, 2:07am
The code you put in the phpincludes template is executed on every page of your forums whether you actually use any of it or not.

Tuan Le
Mon 1st Sep '03, 10:36pm
Go into Admin mode and look down on the left towards the bottom select Edit Templates and click EXPAND in the main window. THe php-include template will be down towards the bottom.

Regards,

Matt


I'm using version 3, beta 4 and can't find this phpinclude template anywhere. :confused: :(

squall14716
Tue 2nd Sep '03, 12:34am
In vB3, there are two phpinclude: phpinclude_start and phpinclude_end. phpinclude_start is the one you're looking for.

Tuan Le
Tue 2nd Sep '03, 1:38pm
In vB3, there are two phpinclude: phpinclude_start and phpinclude_end. phpinclude_start is the one you're looking for.
Thanks. :D I greatly appreciate your help. :D


I got that piece added to phpinclude_start. How about the the local invocation code generated by phpadsnew. Can you please let me know where I need to put it? :confused: Thanks again. :)


<?php
if (@include('C:/../../phpadsnew/phpadsnew.inc.php')) {
if (!isset($phpAds_context)) $phpAds_context = array();
$phpAds_raw = view_raw ('', 2, '', '', '0', $phpAds_context);
echo $phpAds_raw['html'];
}
?>

Tuan Le
Wed 3rd Sep '03, 1:07am
After adding the codes to the phpinclude_start template, I now run into the error below. Any clues? :confused: :( Once again, thanks for the help.

Warning: Unable to access /phpadsnew/phpadsnew.inc.php in /home/virtual/site22/fst/var/www/html/forum/global.php(345) : eval()'d code on line 6

Fatal error: Failed opening required '/phpadsnew/phpadsnew.inc.php' (include_path='.:/usr/share/pear:/php/includes:/usr/share/php') in /home/virtual/site22/fst/var/www/html/forum/global.php(345) : eval()'d code on line 6

Futuredood
Tue 17th Feb '04, 3:39pm
EDIT:

I had problems getting a php script to execute but I finally got it working. For anyone interested, this is probably not the best solution but it works for me...

ob_start();
chdir("/path/to/script");
require("script.php");
chdir("/path/to/forum");
$execute_script = ob_get_contents();
ob_end_clean();
and you just put this in php_include? (in vbulletin 3)

Steve Machol
Tue 17th Feb '04, 4:08pm
phpinclude_start or phpinclude_end depending on exactly what you are trying to do.

Futuredood
Tue 17th Feb '04, 6:02pm
phpinclude_start or phpinclude_end depending on exactly what you are trying to do.
I'm trying to execute a perl script located here:

http://www.aznraps.com/cgi-bin/banner_rotator/ad.pl


I use this code:

ob_start();
chdir("/home/aznraps/cgi-bin/banner_rotator/");
require("ad.pl");
chdir("/home/aznraps/public_html/forums");
$execute_script = ob_get_contents();
ob_end_clean();

What shows up is blank. Is there a different code needed to include a .pl file?

Darkwaltz4
Fri 27th Feb '04, 6:57am
um, no matter what you include it will try to spit out as html. depending on whats in your file, you might have to edit the file to get it to display like you want.

and your problem can be fixed one of two ways.

1) in the first chdir statement, remove the trailing slash

or

2) in the require statement, instead of file.ext, make it ./file.ext

i would suggest you place this in phpinclude_start since its not dependant on any forum variables and ads usually are displayed near the top :)

KW802
Sun 28th Mar '04, 2:49am
To use Includes in your forums, you need to add this to your 'phpinclude' template:


ob_start();
require("/path/to/include/file");
$file = ob_get_contents();
ob_end_clean();


Replace '/path/to/include/file' with the path to the file you want to include.
Then put '$file' in the templates where you want your included file to display.

:cool: Cool, thanks for the tip. Using this I was able to change my header & footer templates to use the same .htm files that my main page uses so now I can modify one common file instead of two. :)

eblivion
Sat 25th Sep '04, 11:18am
How do I call the file from a new template that I created?

Your instructions work great when I used it in one of the existing templates but when I tried calling it from a template I created, nothing appears where the content should be.

scruby
Fri 4th Mar '05, 2:10am
include isn't a replacement for virtual. virtual fires off an apache subrequest, and include does not. What this means is that if you need to include a cgi which relies on environment variables set by apache you are out of luck. examples would be traffic trading scripts, geo-targeted banners, and a multitude of other stuff. This is a problem for version 3 as well as version 2 of vBulletin, and I'm pretty sure that if someone from Jelsoft answers this post they'll agree that firing off of a subrequest from within vbulletin can't be done easily or at all.:(

scruby
Sat 5th Mar '05, 2:52am
The problem is you want to run a script that requires the server variables from the original request, but you can't do it because there's no way for php to capture the output of a subrequest into a variable.

A further explaination is in http://bugs.php.net/bug.php?id=7008


// NO GOOD because referer, remote address, x_forwarded_for,
// and other server variables are lost

ob_start();
include('http://www.yoursite.com/cgi-bin/ttt-in');
$ttt_in = ob_get_contents();
ob_end_clean();

// NO GOOD because output buffering doesn't work for virtual()

ob_start();
virtual('/cgi-bin/ttt-in');
$ttt_in = ob_get_contents();
ob_end_clean();

Here's the workaround:

putenv('REQUEST_METHOD=GET');
putenv("REMOTE_ADDR=".$_SERVER['REMOTE_ADDR']);
putenv('SCRIPT_NAME=/cgi-bin/ttt-in');
putenv('QUERY_STRING='.$_SERVER['QUERY_STRING']);
if($_SERVER['HTTP_COOKIE'])
{
putenv("HTTP_COOKIE=".$_SERVER['HTTP_COOKIE']);
}
if($_SERVER['HTTP_REFERER'])
{
putenv("HTTP_REFERER=".$_SERVER['HTTP_REFERER']);
}
if($_SERVER['HTTP_X_FORWARDED_FOR'])
{
putenv("HTTP_X_FORWARDED_FOR=".$_SERVER['HTTP_X_FORWARDED_FOR']);
}
unset($return_array);
$cwd = getcwd();
chdir('/var/www/cgi-bin/');
exec('/var/www/cgi-bin/ttt-in', $return_array, $return_val);
chdir($cwd);
$return_array = array_slice($return_array,1);
setcookie('i',substr(array_shift($return_array),14 ));
$ttt_in = implode(array_slice($return_array,5),"\n");

It's messy. You have to set environment variables, and parse the output of the script, but it can be done!

webfire
Tue 12th Apr '05, 4:29pm
I cannot get this to work!!!! It seems so simple.

Here is what I have in phpinclude_start

ob_start();
require("../am/publish/search_form.shtml");
$file = ob_get_contents();
ob_end_clean();


And in my header template:

<td>$file</td>

Nothing happens. The souce doesn't show anything. Just <td></td>.

sere
Fri 29th Apr '05, 7:40am
I had some issues as well using the following code


ob_start();
include_once('/path/to/file.php');
$shortstat = ob_get_contents();
ob_end_clean();


When included in phpinclude_start after logging in instead of going back to index it was going to homepage/Array directory. Now I've included it in phpinclude_end and it seems to work. Does anyone know what is the difference between the two (_start and _end) ?

Nirex
Tue 19th Jul '05, 10:08am
Wassssssap Yo!??!!!!!!!!!!!!!!!!!
Wassssssap Yo!??!!!!!!!!!!!!!!!!!

Wassssssap Yo!??!!!!!!!!!!!!!!!!!

Wassssssap Yo!??!!!!!!!!!!!!!!!!!

Wassssssap Yo!??!!!!!!!!!!!!!!!!!

Wassssssap Yo!??!!!!!!!!!!!!!!!!!






Wassssssap Yo!??!!!!!!!!!!!!!!!!!











Wassssssap Yo!??!!!!!!!!!!!!!!!!!







Wassssssap Yo!??!!!!!!!!!!!!!!!!!






Wassssssap Yo!??!!!!!!!!!!!!!!!!!