Hello everyone, I have an issue that I can't seem to resolve with integrating phpBB into the rest of my site so that login and session can be intact. Well, for the most part, the whole scheme seems to work at first glance. I noticed that pages that have the phpBB root path and includes and other initialization stuff works like a charm. I can pull up $userdata and what have you very nicely. I do have my own include file that has functions I use to generate menus and other things. These functions don't react to any of the $userdata.

He he he he. After reading several pages about integrating phpBB into your main site through it's session capability, I came to realize that the answer was not in the actually integration code. This will solve a lot of headaches for noobs like myself, but if you have a external file of functions that need to use the $userdata that the page including the external file has already established, all you have to do is put into the function "global". This is an example of what I am talking about.
Member only page

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

// Start session management
$userdata = session_pagestart($user_ip, PAGE_LOGIN);
// End session management
$page_title = "Catalog";
include("misc.php"); // <---EXTERNAL FILE
<title>Whatever you want</title>
<link href="./mainstyle.css" rel="stylesheet" type="text/css" />
<script type="text/JavaScript" src="mainscript.js"></script>
<?php generateSomething(); ?>

Well this is what the external include misc.php will have to look like....

$connection = mysql_connect(localhost,db_username,db_password)
    or die("Couldn't connect to database!<br>");
$database = "db_name"; //Database containing the tables for the chat logs
$db = mysql_select_db($database,$connection) 
    or die ("Database not selected!");
function generateSomething(){
global $userdata;
echo "This is all it generates!? Booo.<br />";
if ($userdata['session_logged_in']){
   echo "Well this is cool though, Your username is ".$userdata['username']."!!!!";

Well, thats the whole idea. I might have made some coding errors or something but
just so that if anyone runs into this problem there is at least something for those new to php like me to hint this, and save an hour or two of needless searching. PS. don't forget to append $userdata to any link that you need to have access to the login credentials. I manually echo it into the address instead of using the append_sid() which works for me, but thats just me. :) Thanks you all for your time.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.