If you have a PHP or HTML file that you want to include in your vBulletin forum, create a plugin that references that file. Then add a variable to the template of your choice where that file's contents should appear.
Including an HTML file:
1. Create a Plugin for global_start with this code:
PHP:
$includedhtml = implode('', file('path/to/this/file/myfile.html'));
replacing the path and filename with the correct path and filename of the HTML file you want to include. The contents of myfile.html will be copied to the variable
2. Place
in one of your templates, such as header, navbar, FORUMHOME, depending upon where you want the contents of your HTML file to appear.
Note: The Plugin system must be enabled in vBulletin Options -> Plugin System for plugins to work. It is disabled by default.
Including a PHP file:
1. Create a Plug-in for global_start with these contents:
PHP:
ob_start();
include('path/to/this/file/myfile.php');
$includedphp = ob_get_contents();
ob_end_clean();
replacing the path and filename with the correct path and filename of the PHP file you want to include. The code in myfile.php will execute and any output generated by this script will be stored in $includedphp.
2. Place
in one of your templates, such as header, navbar, FORUMHOME, depending upon where you want the contents of your PHP file to appear.
Note: The Plugin system must be enabled in vBulletin Options -> Plugin System for plugins to work. It is disabled by default.
WARNING: Plugins that contain invalid or malicious code may cause your forum to stop functioning or even lead to data loss. If a Plugin has made your forum inaccessible, disable the plugins.
What are ob_start(), ob_get_contents(), ob_end_clean(), etc? What is Output Buffering?
Most PHP files that you might wish to include in your forum contain echo or other output statements in your PHP file, it will break vBulletin because it is still in the process of initializing when it loads your PHP file. All echo and other output commands must be output buffered using ob_start, ob_clean, etc. commands. The output of your PHP script will be buffered for later use and inserted into a variable. All other statements in the PHP script will execute normally.
A word about variables.
It is very important that any variables initialized in your PHP script do not overlap built-in vBulletin variables or you will get unpredictable results. It may be advisable to create a PHP script just for inclusion in your forum rather than including a larger script used by another part of your website.
Which hook should I use?
The hook I've used above (global_start) makes your HTML or PHP file available in almost every template on your vBulletin forum. You may wish to include a PHP file or HTML file only on certain pages or parts of your forum. You'll need to select the correct hook where your code should be loaded. To determine which hook you should use, turn on Debug and then make this change to the appropriate functions php file.
Note: If you wish to include() multiple PHP files, make sure you use ob_clean() before each include() to reset the buffer.