• twitter image
  • facebook image
  • youtube image
  • linkedin image
Language: CMS Made Simple Czech CMS Made Simple France CMS Made Simple Spain CMS Made Simple Hungary CMS Made Simple Russia CMS Made Simple Netherlands

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: CMSMS & PHPBB Forum Session Sharing
PostPosted: Tue Nov 05, 2019 12:12 am 
Offline
Forum Members
Forum Members
User avatar

Joined: Thu Mar 24, 2011 12:37 am
Posts: 94
Hi guys i was building a project where the main domain shares the same header menu with a phpbb forum located at a subdomain. Similar to cmsms site and forum.

CMSMS v2.2.12
PHPBB v3.2.7

phpbb has some tutorials on how to get the user session and display it into a template:
\$1:
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);
$user->session_begin();
$auth->acl($user->data);
$user->setup();
global $template;
page_header('Login Bar');
$template->set_filenames(array(
    'body' => 'top_bar.tpl',
));
//print_r($user->data);
page_footer();


The problem i was facing was functions conflict when "include" in my custom function or in my custom module.

The way i worked around this problem was getting the user's cookie and creating my own database query:

\$1:
$cookie = $_COOKIE["v2_btg_forum_sid"];
if( !$cookie ) exit;
$db = new conn_forum; //database connection to your forum
$db->connect();
$sql = "SELECT s.session_id, s.session_ip, s.session_user_id, u.user_type, u.username, u.user_last_privmsg FROM phpbb_sessions s
LEFT JOIN phpbb_users u ON s.session_user_id = u.user_id
WHERE session_id = '".$cookie."'";
$result=$db->query($sql);

    while($row = mysqli_fetch_assoc($result)){
        $privmsgs = privmsgs($db,$row['session_user_id']);
        $session = array(
                            'session_id'=> $row['session_id'],
                            'session_user_id'=> $row['session_user_id'],
                            'username'=> $row['username'],
                            'session_ip'=> $row['session_ip'],
                            'pm_new' => $privmsgs['pm_new'],
                            'pm_unread' => $privmsgs['pm_unread'],
                            'user_type' => $row['user_type']
                              );
    }

if($session['session_user_id'] > 1){
    $tpl = $smarty->CreateTemplate($this->GetTemplateResource('login_bar.tpl'),null,null,$smarty);
    $tpl->assign('session',$session);

    $tpl->assign('U_PROFILE', 'https://'.FORUM_DOMAIN . '/ucp.php');
    $tpl->assign('U_BOOKMARK', 'https://'.FORUM_DOMAIN . '/ucp.php?i=main&mode=bookmarks');
    $tpl->assign('U_LOGIN_LOGOUT', 'https://'.FORUM_DOMAIN . '/ucp.php?mode=logout&sid='.$cookie);
    $tpl->assign('U_PRIVATEMSGS', 'https://'.FORUM_DOMAIN . '/ucp.php?i=pm&folder=inbox');

    if($session['pm_unread'] > 0) {
        $tpl->assign('PRIVATE_MESSAGE_COUNT',$session['pm_unread']);
    }

    $tpl->display();
    //echo json_encode($session);
}

function privmsgs($db,$uid){
    $sql = "SELECT sum(pm_new) AS pm_new,sum(pm_unread) AS pm_unread FROM phpbb_privmsgs_to WHERE user_id = $uid";
    $result=$db->query($sql);
    while($row = mysqli_fetch_assoc($result)){
        $array = array('pm_new'=> $row['pm_new'], 'pm_unread'=> $row['pm_unread']);
    }
    return $array;
}


This will provide you with the data, you then need to attache the login_bar.tpl template and process the variables.
Hope this helps.


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
A2 Hosting