Would you like to see a new MOD created?

Support Forum · Home phpBB 2.0.x Support Integrating a .php page into your phpBB forum

This is a very simple tutorial detailing how to integrate a .php into phpBB within minutes. This is commonly known as sessions integration.

Firstly, ensure that the top of the .php file looks like this:

define('IN_PHPBB', true); defines that the page is simply a part of phpBB.

$phpbb_root_path = './'; shows the path to the forum. If the .php is within the forum directory, you can leave this as is. However, if your forum is in the phpBB2/ folder, one level above root, and your .php file is in root, then it will need to be configured to reflect this, by setting it to $phpbb_root_path = './phpBB2/';

The two include functions connect to vital phpBB files, with holding the page extension (usually .php) and common.php connecting to the core phpBB files, which make the use of phpBB functions and database connections easily useable.

The session management area handles the users login information, including all $userdata variables (more about this can be read in the $userdata variables tutorial.

If you want to display the forum header, directly below the above code, enter:

Should you want to use .tpl files, you would then enter the following code. Bear in mind, this is not necessary, you can just as easily use echo statements to output HTML code (briefly explained below).

Replace filename_body.tpl with your true filename. For example, it may look like statistics_body.tpl or friends_body.tpl.

To pass variables through to a template (.tpl) file, include this code:

In your .tpl file (which must be uploaded to templates/subSilver/ or your equivalent template) to output a variable, you enclose the variable name in parenthesis. For instance, to display the text "Variable 1", you would include {VAR1} in the .tpl file.

As I said earlier, it is just as easy to use HTML in the .php file. Suppose you wanted to simply display a "Hello, username! You have xxx posts" text on the page. You could use this HTML/PHP combination. Ignoring the templating code above, directly after the include($phpbb_root_path . 'includes/page_header.'.$phpEx); you would include:

To guests, this would say "Hello Anonymous! You have 0 posts". To all other users, it would display their username and post count.

If you were using the templating code for .tpl files as above, before the end of the file, you must include $template->pparse('body');

If you including page_header.php, you must also include page_tail.php by entering include($phpbb_root_path . 'includes/page_tail.'.$phpEx);

. To finish the file, type ?> as this closes the PHP script.

In all, your file might look something like this: