XF 1.2 XF - MemcacheD - CometChat - "Works Now :-)"

Bill.D

Active member
Hey All,

My problem with CometChat was Finaly resolved and I just wanted to share what they & I did.

Here is the code from the integration.php that they changed:
PHP:
function getUserID() {
    $userid = 0;
 
    if (!empty($_SESSION['basedata']) && $_SESSION['basedata'] != 'null') {
        $_REQUEST['basedata'] = $_SESSION['basedata'];
    }
    if (!empty($_REQUEST['basedata'])) { 
        /*if (function_exists('mcrypt_encrypt')) {
            $key = KEY_A.KEY_B.KEY_C;
            $uid = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($_REQUEST['basedata']), MCRYPT_MODE_CBC, md5(md5($key))), "\0");
            if (intval($uid) > 0) {
                $userid = $uid;
            }
        } else {*/
            $userid = $_REQUEST['basedata'];
        //}
    }

    if (!empty($_COOKIE['xf_session'])) {
        $sql = ("SELECT `session_data` FROM  `".TABLE_PREFIX."session` WHERE `session_id` = '".$_COOKIE['xf_session']."'");        $query = mysql_query($sql);
        $sess2 = mysql_fetch_array($query);
        $sess3 = unserialize($sess2[0]);
        $userid = $sess3['user_id'];
    }    $userid = intval($userid);

    if (!empty($_COOKIE['xf_user'])) {
        $a = explode(',',$_COOKIE['xf_user']);
        $userid = $a[0];     
    }
/*
    if (!empty($_COOKIE['xf_session'])) {     
        $sql = ("SELECT `session_data` FROM  `".TABLE_PREFIX."session` WHERE `session_id` = '".$_COOKIE['xf_session']."'");        $query = mysql_query($sql);
        $sess2 = mysql_fetch_array($query);
        $sess3 = unserialize($sess2[0]);
        $userid = $sess3['user_id'];
    }*/
    //echo $userid;
    return $userid;
}

Here is the Template change I added to PAGE_CONTAINER:
PHP:
<html id="XenForo" lang="{$visitorLanguage.language_code}" dir="{$visitorLanguage.text_direction}" class="Public {xen:if {$visitor.user_id}, 'LoggedIn', 'LoggedOut'} {xen:if {$sidebar}, 'Sidebar', 'NoSidebar'} {xen:if $hasAutoDeferred, RunDeferred} {xen:if $isResponsive, Responsive, NoResponsive}" xmlns:fb="http://www.facebook.com/2008/fbml">
<head>

<!--- CometChat 5.1.0 START --->

<script type="text/javascript">
var userid = {$visitor.user_id};
document.cookie = "xf_user="+userid;
</script>

<link type="text/css" href="http://XXX.XXXXXXX.com/cometchat/cometchatcss.php" rel="stylesheet" charset="utf-8">
<script type="text/javascript" src="http://XXX.XXXXXXX.com/cometchat/cometchatjs.php" charset="utf-8"></script>

<!--- CometChat 5.1.0 END --->

<xen:hook name="page_container_head">
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />

Note: the Script where the userid variable is declared and then set to the cookie :)

If anyone thinks of a better way this all should be done.. Let me know :)
 
Important Update!:

There was an error in the code they gave! It ends up conflicting with a Xenforo cookie entry when you log in and choose "Keep me Logged in".

Here is the updated Code:
PHP:
/* FUNCTIONS */

function getUserID() {
    $userid = 0;
   
    if (!empty($_SESSION['basedata']) && $_SESSION['basedata'] != 'null') {
        $_REQUEST['basedata'] = $_SESSION['basedata'];
    }
    if (!empty($_REQUEST['basedata'])) {   
        $userid = $_REQUEST['basedata'];   
       
    }
    if (!empty($_COOKIE['cc_xf_user'])) {
        $a = explode(',',$_COOKIE['cc_xf_user']);
        $userid = $a[0];    
    }   
    return $userid;
}
PHP:
<script type="text/javascript">
var userid = {$visitor.user_id};
document.cookie = "cc_xf_user="+userid;
</script>

In order to clear the CometChat Cache you need to delete the contents of the Cache folder within the CometChat Folder! Otherwise it won't work until it updates its own cache.
 
Last edited:
Important Update!:

There was an error in the code they gave! It ends up conflicting with a Xenforo cookie entry when you log in and choose "Keep me Logged in".

Here is the updated Code:
PHP:
/* FUNCTIONS */

function getUserID() {
    $userid = 0;
  
    if (!empty($_SESSION['basedata']) && $_SESSION['basedata'] != 'null') {
        $_REQUEST['basedata'] = $_SESSION['basedata'];
    }
    if (!empty($_REQUEST['basedata'])) {  
        $userid = $_REQUEST['basedata'];  
      
    }
    if (!empty($_COOKIE['cc_xf_user'])) {
        $a = explode(',',$_COOKIE['cc_xf_user']);
        $userid = $a[0];   
    }  
    return $userid;
}
PHP:
<script type="text/javascript">
var userid = {$visitor.user_id};
document.cookie = "cc_xf_user="+userid;
</script>

In order to clear the CometChat Cache you need to delete the contents of the Cache folder within the CometChat Folder! Otherwise it won't work until it updates its own cache.
Hi Bill,

I have a same problem with cometchat 5.5.0. At first I cant be online at cometchat, so I see your article and I have made changes. After that I can be online but I cant see anyone now.
Is there anyway to change this ?

Thanks.
 
Top Bottom