Bad Boy Blog, an unofficial Diddy and Bad Boy fan blog

Bookmark and Share

Creating a New phpBB 3 Page

Creating a New phpBB 3 Page

Postby Thoul » February 3rd 2013, 3:43 pm

This tutorial is intended to teach you how to create new pages that use phpBB 3.0's session and login controls, or how to use these features on non-phpBB pages. This can allow your users to log in once for your whole site and allow you to restrict access to pages based on logged in status or group membership.

Here is the code needed to create a basic page that integrates with phpBB 3.0 and uses phpBB's template system to display content. You can name the page as suits your needs; a schedule might be named schedule.php. To use the code provided in this example, you would also need to create a file called your_page.html, which would contain the content you wish to display on your page. Place a copy of your_page.html inside the template folder of each style installed on your board. Again, you can change this name - say schedule.html, for example. If you do so, remember to change the name referenced in this code as well.

Code: Select all
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

// Start session management

$page_title = 'Your Custom Page Title Here';

// Additional features to restrict access can be added here.

page_header($page_title, false);

	// your_page.html should be changed if you change
	// the name of your template file.
	'body'	=> 'your_page.html',


Restricting Access
There are many ways you can restrict access to a page to certain users. In the above block of code, you can see the line, // Additional features to restrict access can be added here. By adding one of the optional snippets of code below to that area, you can limit who can see your page.

Restricting to Certain Groups
Code: Select all
// To restrict the page to members of a group, enter a 
// comma separated list of group ids here. For example:
// $allowed_groups = array(1, 2, 3);
$allowed_groups = array();

include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
if (!group_memberships($allowed_groups, $user->data['user_id'], true))

Restricting to Administrators and Moderators
Code: Select all
// $auth->acl_get('a_') checks to see if the user is an admin
// $auth->acl_get('m_') checks to see if the user is a moderator
if(!($auth->acl_get('a_') || $auth->acl_get('m_')))

Restricting to Logged In Users
Code: Select all
if (!$user->data['is_registered'])
	// Show a login form

Including Header and Footer
Our example page, in the first code block above, uses the phpBB template system to display your content from the your_page.html file. Below is an example of the your_page.html file. In this example, the first line will cause the page to include phpBB's page header. The last line will include phpBB's page footer.
Code: Select all
<!-- INCLUDE overall_header.html -->

Your content would go here

<!-- INCLUDE overall_footer.html -->
User avatar
Posts: 18551
Joined: July 30th 2002, 11:30 am
Location: USA

Return to phpBB 3: Customizing Your phpBB

Who is online

Users browsing this forum: No registered users and 0 guests