1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to get session data when using back-end cache

Discussion in 'XenForo Development Discussions' started by adwolf1, Sep 20, 2014.

  1. adwolf1

    adwolf1 Active Member

    dumb question -- i'm trying to troubleshoot a third-party plugin (chat) that integrates with XF's login/sessions, as it should automatically log in any user that has an established XF session.

    The problem i'm having is this -- i'm using memcached as a back-end cache, and from what I can tell that means it is caching sessions in memory (the table xf_session is blank)

    Unfortunately, some code in the add-on looks like this:

     if (!empty($_COOKIE['xf_session'])) {       
            $sql = ("SELECT `session_data` FROM  `".TABLE_PREFIX."session` WHERE `session_id` = '".$_COOKIE['xf_session']."'");        $query = mysqli_query($GLOBALS['dbh'],$sql);
            $sess2 = mysqli_fetch_assoc($query);
            $sess3 = unserialize($sess2['session_data']);
            if(!empty($sess3['user_id'])) {
                $userid = $sess3['user_id'];
            } else {
                $userid = 0;
    It is trying to query the database to get the session data, and failing b/c it finds nothing there.

    What's the proper way to do this when sessions are being cached?

  2. Jeff Berry

    Jeff Berry Well-Known Member

    Have you tried using something like this?

    $xfSession XenForo_Session::getPublicSession(XenForo_Application::getFc()->getRequest());
    Not sure how "third party" the plugin you're working with is, but the above line would normally give you the XF session.

Share This Page