How do I get my website working with the CometChat App for iPhone and Android?

In order to use CometChat mobile app with your website, you need to make sure that you are using CometChat version 5.0.0+

Also, refer to the following steps for troubleshooting any login issues:

1. If you have white labelled CometChat on your web site, then please use http://<your site URL>/<white labelled name for cometchat>/ as URL.

for example: http://www.mysite.com/
mywhitelabelledcometchat/

2. If you are getting an error message “Username and password do not match” then please make sure you have configured chatLogin function correctly.

This function takes username/email and password as input and returns encrypted userID (primary key of your site’s users table) after authenticating user based on your authentication mechanism.

For example:


function chatLogin($userName, $userPass) {

    $userid = 0;
    if (filter_var($userName, FILTER_VALIDATE_EMAIL)) {
        $sql = ("SELECT * FROM `".TABLE_PREFIX.DB_USERTABLE.
            "` WHERE email ='".$userName.
            "'");
    } else {
        $sql = ("SELECT * FROM `".TABLE_PREFIX.DB_USERTABLE.
            "` WHERE username ='".$userName.
            "'");
    }
    $result = mysqli_query($GLOBALS['dbh'], $sql);
    $row = mysqli_fetch_assoc($result);
    $salted_password = md5($row1['value'].$userPass.$row['salt']);
    if ($row['password'] == $salted_password) {
        $userid = $row['user_id'];
        if (isset($_REQUEST['callbackfn']) && $_REQUEST['callbackfn'] == 'mobileapp') {
            $sql = ("insert into cometchat_status (userid,isdevice) values ('".mysqli_real_escape_string($GLOBALS['dbh'], $userid).
                "','1') on duplicate key update isdevice = '1'");
            mysqli_query($GLOBALS['dbh'], $sql);
        }
    }
    if ($userid && function_exists('mcrypt_encrypt') && defined('ENCRYPT_USERID') && ENCRYPT_USERID == '1') {
        $key = "";
        if (defined('KEY_A') && defined('KEY_B') && defined('KEY_C')) {
            $key = KEY_A.KEY_B.KEY_C;
        }
        $userid = rawurlencode(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $userid, MCRYPT_MODE_CBC, md5(md5($key)))));
    }

    return $userid;
}

3. Please make sure you have added the following code in getUserID function after $userid=0; like:

function getUserID() {
    $userid = 0;
    if (!empty($_SESSION['basedata']) && $_SESSION['basedata'] != 'null') {
        $_REQUEST['basedata'] = $_SESSION['basedata'];
    }

    if (!empty($_REQUEST['basedata'])) {

        if (function_exists('mcrypt_encrypt') && defined('ENCRYPT_USERID') && ENCRYPT_USERID == '1') {
            $key = "";
            if (defined('KEY_A') && defined('KEY_B') && defined('KEY_C')) {
                $key = KEY_A.KEY_B.KEY_C;
            }
            $uid = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode(rawurldecode($_REQUEST['basedata'])), MCRYPT_MODE_CBC, md5(md5($key))), "");
            if (intval($uid) > 0) {
                $userid = $uid;
            }
        } else {
            $userid = $_REQUEST['basedata'];
        }
    }
    if (!empty($_SESSION['userid'])) {
        $userid = $_SESSION['userid'];
    }

    $userid = intval($userid);
    return $userid;
}

Not finding what you need?

The CometChat team is here to help!