Managing Online Forums, a manual for the community admin

Bookmark and Share

phpBB/Login and Site Integration

phpBB/Login and Site Integration

Postby Kai WT » February 14th 2003, 11:36 pm

I'm going to try and make this as easy to follow as possible, please feel free to suggest improvements via private message.

This tutorial is designed to show you how to put non phpBB pages under phpBB's sessions and login control, to let your users log in once for your whole site and to be able to restrict access to pages to logged in members or by usergroup.

Okay, here's the code, not in a code block because the colors help. :) You can name the page whatever you want. Say if its a schedule, schedule.php.

<?php
define('IN_PHPBB',true);

$phpbb_root_path = "./"; // set path to phpBB files
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);

//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_LOGIN); // initiate session
init_userprefs($userdata); // load user prefs
//
// End session management
//
$page_title = "Title of Page Goes Here";


$userid = $userdata['user_id'];
$sql = "SELECT * FROM " . USER_GROUP_TABLE . " WHERE user_id = '$userid'";
$result = $db->sql_query($sql);
$isauth = 0;
while ($row = $db->sql_fetchrow($result))
{
if ($row['group_id'] == 'insert_group_id_here' || $row['group_id'] == 'insert_group_id_here')
{
$isauth = 1;
}
}





if($userdata['session_logged_in'])
{ // user is logged in


include($phpbb_root_path . 'includes/page_header.'.$phpEx);
if ($isauth == '1')
{
Insert content here
}
else
{
message_die(GENERAL_ERROR, "You do not have permission to access this page");
}

}
else
{ // not logged in
header('Location: ' . append_sid($phpbb_root_path.'login.'.$phpEx.'?redirect='.basename($HTTP_SERVER_VARS['PHP_SELF']), true));
}


include($phpbb_root_path . 'includes/page_tail.'.$phpEx);

?>

The normal text is what you need to have the page use the same user session and style as the rest of the phpBB pages. If you want to make people log in before being allowed to view the page, use the blue code as well. The violet code adds the header and footer from phpBB onto the top and bottom of your page, respectively. The red is what you need to set if you only want specific usergroups to be able to access the page. Green is obviously where your content goes.

The only thing to remember is that the pages must be in the same directory as the phpBB 2 index file or they will not be able to use the phpBB 2 session.
User avatar
Kai WT
Well Known User
 
Posts: 109
Joined: December 13th 2002, 6:12 pm

Return to phpBB 2: Integrating phpBB With Your Website

Who is online

Users browsing this forum: No registered users and 0 guests