Jump to content

Getting phpBB session data using function


rtadams89

Recommended Posts

I have phpBB 3.0.3 installed and working great.

 

I am trying to use the phpBB user data on other pages of my site (not phpBB related). For example, I have one page which I only want displayed to currently logged in forum members, who belong to the phpBB group #7 or #8. Here is the current code of that page:

 

<?require($_SERVER['DOCUMENT_ROOT'].'/includes/functions.php');?>
<?

define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : $_SERVER['DOCUMENT_ROOT'].'/forum/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();

$username = $user->data["username"];
$uid = $user->data["user_id"];

if (($user->data["is_registered"]) && (($user->data['group_id'] ==  || ($user->data['group_id'] == 7))){
$auth = 2; //Logged in as Coach/Officer
}

elseif (($user->data["is_registered"]) && ($user->data['group_id'] !=  && ($user->data['group_id'] != 7)){
$auth = 1; //Logged in as player
}

else{
$auth = 0; //Not logged in
}

if ($auth == 2)
{
//Display "secret" content here
}
?>

 

This works fine. However, I will be using the $auth variable on multiple pages. I would therefor like to place all of the above code in a function inside "functions.php" (included at the top of each page). I though I could just create a function like that:

 

function phpbb_auth()
{
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : $_SERVER['DOCUMENT_ROOT'].'/forum/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();

$username = $user->data["username"];
$uid = $user->data["user_id"];

if (($user->data["is_registered"]) && (($user->data['group_id'] ==  || ($user->data['group_id'] == 7))){
$auth = 2; //Logged in as Coach/Officer
}

elseif (($user->data["is_registered"]) && ($user->data['group_id'] !=  && ($user->data['group_id'] != 7)){
$auth = 1; //Logged in as player
}

else{
$auth = 0; //Not logged in
}
return $auth;
}

 

and then place "phpbb_auth();" at the top of my content page. This always results in a 500 error when viewing the page. I don't know if the problem is in the way  I Construct and call the function, or if it is a limitation of phpBB. Any help?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.