Including External Files 
Warning:
This is considered modifying the code. To get further help and support with including external files you will need to visit http://www.vbulletin.org/.
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.
Note:
The Plugin system must be enabled in vBulletin Options -> Plugin System for plugins to work. It is disabled by default.
Including an HTML file:
1. Create a Plugin for global_start with this code:
$includedhtml = implode('', file('path/to/this/file/myfile.html'));
Replace 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 $includedhtml.

2. Place {vb:raw includedhtml} in one of your templates, such as header, navbar, FORUMHOME, depending upon where you want the contents of your HTML file to appear.


Including a PHP file:
1. Create a Plug-in for global_start with these contents:
  ob_start();
  include('path/to/this/file/myfile.php');
  $includedphp = ob_get_contents();
  ob_end_clean();
Replace 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 {vb:raw includedphp} in one of your templates, such as header, navbar, FORUMHOME, depending upon where you want the contents of your PHP file to appear.
Warning:
Plugins that contain invalid or malicious code may cause your forum to stop functioning or even lead to data loss. Using Plugins is not supported and you'll be asked to disable them in the event that you request tech support. If a Plugin has made your forum inaccessible, please disable plugins. Troubleshooting errant plugins and products is handled at our sister site, http://www.vBulletin.org.
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.

Variables are also subject to scope. You may need to access your variable out of the $global array like {vb:raw global.variablename} instead of simply {vb:raw variablename}. You may also need work with a hook location that is more accessible to the template that you wish to alter.

Please see the PHP documentation for more information on variable scope:
http://www.php.net/manual/en/language.variables.scope.php

Registering Variables
In vBulletin 4+, you need to register variables for them to be available in specific templates and usable. You would do this with code like this:
vB_Template::preRegister('FORUMHOME',array('includedphp ' => $includedphp));  
Replace FORUMHOME with the template you want to include your value in.

Which hook should I use?

The hook 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.

How do I turn on debug mode?

Please note that you should not turn on debug mode in a live environment.

Open the config.php file.
At the top, on a new line below <?php
add: $config['Misc']['debug'] = true;
Note:
If you wish to include() multiple PHP files, make sure you use ob_clean() before each include() to reset the buffer.
User Contributed Notes: Including External Files Add a Comment
Zachariah Boren 05th Feb 2008, 11:48am
Debug mode can also be turned on with a plugins. I will list 2 examples, Globally and AdminCP only, depending on your need.

** Globally:
AdminCP => Plugins & Products => Add New Plugin

Title: Debug Mode
Hook Location: global_start
PHP Code: $vbulletin->debug = true;


** AdminCP Only:
AdminCP => Plugins & Products => Add New Plugin

Title: Debug Mode AdminCP
Hook Location: admin_global
PHP Code: $vbulletin->debug = true;
Joe Schmitt 14th Feb 2012, 04:22pm
The ( global_start ) hook is deprecated, use ( global_bootstrap_init_start ) instead.

From the global.php file:
// Deprecated as of release 4.0.2, replaced by global_bootstrap_init_start
($hook = vBulletinHook::fetch_hook('global_start')) ? eval($hook) : false;
Add a Comment