Knowledge Base

Coding new pages
Article ID: 83
Written By: aled owen
Written On: Sun Jun 03, 2007 1:29 pm
Description: This article helps people when they are to build a page on their site which integrates with phpBB2.
link to this article on phpbb.com: Select All
[kb=coding-new-pages]Coding new pages[/kb]
link to this article on your own board: Select All
[url=http://www.phpbb.com/kb/article/coding-new-pages/]Knowledge Base - Coding new pages[/url]

This article explains how to use phpBB for authorization and such things on a website. First of all, we need to make sure that the pages you are going to make dynamic are in php. Therefore, the page should look something like this,
Code: Select all
'index.php' or 'things.php'

and not like this,
Code: Select all
'default.asp' or index.html'


The first thing on our phpBB integrated page is the session data. This code looks something like this:

Code: Select all

define
('IN_PHPBB'true);
$phpbb_root_path './';
include(
$phpbb_root_path 'extension.inc');
include(
$phpbb_root_path 'common.'.$phpEx);

//
// Set page ID for session management
//
$userdata session_pagestart($user_ipPAGE_LOGIN);
init_userprefs($userdata);
//
// End session management
//
  


Let me explain all this, first of all. Let's look at this line of code.

Code: Select all
define('IN_PHPBB', true);


This simply means that we are in the phpBB software, it means that you are allowed to view this page.

Code: Select all
$phpbb_root_path = './';


The code here is relatively simple, it lets us know where to find the phpBB root folder. If the directory list is like this:
Code: Select all
index.php
downloads.php
customise.php
support.php
dev.php
phpBB2/index.php
phpBB2/common.php

Then the string for that would be './phpBB2/'. Like this:
Code: Select all
$phpbb_root_path = './phpBB2/';

Carrying on, the following code simply includes the config.php file and the common.php file for various things.
Code: Select all
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);

This code:
Code: Select all
//
// Set page ID for session management
//
$userdata session_pagestart($user_ipPAGE_LOGIN);
init_userprefs($userdata);
//
// End session management
//
  

Is just the Management of the Session, this is required.

These following PHP commands allow dynamics's for the user.

Code: Select all
$userdata['username'];

This lets the user get the users username.

Code: Select all
$userdata['user_id'];

The ID of the user.

Code: Select all
$userdata['user_rank'];

The rank of the user. User/Admin.

These can be used in If/Else statements, for instance:

Code: Select all
if ($userdata['user_id'] = $_GET['id']) {
     echo 
"Hello. You are " $userdata['username'] . ".";
}
  


Thanks for reading. I hope you have learned something from this article.


Update: Sept 8, 2007 by battye, changed $userdata['userid'] to the correct $userdata['user_id'] variable.