Apps

If you would like to use our Mobile and Desktop Apps, some configuration may be required depending on the product being used.

Product:
You will get chatLogin() in integration.php. Your chatLogin() will look like:

function chatLogin($userName,$userPass) {
   $userid = 0; 
   $sql = ("SELECT * FROM users WHERE username='".$userName."'");
   $result = mysqli_query($GLOBALS['dbh'],$sql);
   $row = mysqli_fetch_assoc($result);  
   $check = md5(md5($userPass));
   if ($check==$row['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 (function_exists('mcrypt_encrypt') && defined('ENCRYPT_USERID') && ENCRYPT_USERID == '1') {
    $key = KEY_A.KEY_B.KEY_C;
       $userid = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $userid, MCRYPT_MODE_CBC, md5(md5($key))));
    }
  return $userid;
}
function chatLogin($userName,$userPass) {
   $userid = 0; 
   $sql = ("SELECT * FROM users WHERE username='".$userName."'");
   $result = sqlsrv_query($GLOBALS['dbh'],$sql);
   $row = sqlsrv_fetch_array($result);  
   $check = md5(md5($userPass));
   if ($check==$row['password']) { 
      $userid = $row['user_id'];
      if (isset($_REQUEST['callbackfn']) && $_REQUEST['callbackfn'] == 'mobileapp') {
        $sql = ("insert into cometchat_status (userid,isdevice) values ('".mssql_real_escape_string($userid)."','1') on duplicate     key update isdevice = '1'");
mysqli_query($GLOBALS['dbh'], $sql);
      }
   }
 if (function_exists('mcrypt_encrypt') && defined('ENCRYPT_USERID') && ENCRYPT_USERID == '1') {
    $key = KEY_A.KEY_B.KEY_C;
       $userid = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $userid, MCRYPT_MODE_CBC, md5(md5($key))));
    }
  return $userid;
}
function chatLogin($userName,$userPass) {
   $userid = 0; 
   $sql = ("SELECT * FROM users WHERE username='".$userName."'");
   $result = sql_query($sql, array(), 1);
   $row = sql_fetch_assoc($result); 
   $check = md5(md5($userPass));
   if ($check==$row['password']) { 
      $userid = $row['user_id'];
      if (!empty($userid) && isset($_REQUEST['callbackfn']) && $_REQUEST['callbackfn'] == 'mobileapp') {
        $sql = ("insert into cometchat_status (userid,isdevice) values ('".sql_real_escape_string($userid)."','1') on duplicate     key update isdevice = '1'");
sql_query($sql, array(), 1);
      }
   }
 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;
}

The chatLogin() returns user id of logged in user if the username and password are authenticated successfully.

In your getUserID() which is in integration.php, add the following code after $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))), "");
     if (intval($uid) > 0) {
      $userid = $uid;
     }
 } else {
  $userid = $_REQUEST['basedata'];
 }
} 
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))), "");
     if (intval($uid) > 0) {
      $userid = $uid;
     }
 } else {
  $userid = $_REQUEST['basedata'];
 }
} 
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))), "");
     if (intval($uid) > 0) {
      $userid = $uid;
     }
 } else {
  $userid = $_REQUEST['basedata'];
 }
} 

So, your getUserID() will look 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')) {
    $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))), "");
      if (intval($uid) > 0) {
       $userid = $uid;
      }
    } else {
    $userid = $_REQUEST['basedata'];
    }
   }
 if (!empty($_SESSION['userid'])){
   $userid = $_SESSION['userid'];
 }
 return $userid;
}
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))), "");
      if (intval($uid) > 0) {
       $userid = $uid;
      }
    } else {
    $userid = $_REQUEST['basedata'];
    }
   }
 if (!empty($_SESSION['userid'])){
   $userid = $_SESSION['userid'];
 }
 return $userid;
}
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))), "");
      if (intval($uid) > 0) {
       $userid = $uid;
      }
    } else {
    $userid = $_REQUEST['basedata'];
    }
   }
 if (!empty($_SESSION['userid'])){
   $userid = $_SESSION['userid'];
 }
 return $userid;
}
If you would like to use our Mobile and Desktop Apps with CometChat Cloud, please get in touch with us.
  • Was this helpful?
  • Yes   No