Authentication

Introduction

Product:

Update single-sign-on functionality

The getUserID() function is used to return the logged in user’s ID which is in integration.php. Depending on how you have programmed your site, You will have to find out the user’s ID.

If you have written a simple PHP authentication, then during the authentication, you can specify a session variable like:

/* In your own login.php */
/* After you authenticate the user */
$_SESSION['userid'] = $users['id']; // Modify to suit requirements

Then your getUserID() function will look like:

function getUserID() {
  $userid = 0; // Return 0 if user is not logged in
  if (!empty($_SESSION['userid'])) {
      $userid = $_SESSION['userid'];
  }
  $userid = intval($userid);
  return $userid;
}

If you are using a cookie then configure the same using the following function:

function getUserID() {
  $userid = 0; // Return 0 if user is not logged in
  if (!empty($_COOKIE['userid'])) {
    $userid = $_COOKIE['userid'];
  }
  $userid = intval($userid);
  return $userid;
}

If you are using a more complex method of authentication like storing the session_hash in the database, then your getUserID() function will look something like:

function getUserID() {
    $userid = 0; // Return 0 if user is not logged in
    if (!empty($_COOKIE['sessionhash'])) {
    $sql = ("select userid from ".TABLE_PREFIX."session 
            where sessionhash = '".mysql_real_escape_string($_COOKIE['sessionhash'])."'");
        $query = mysql_query($sql);
        $session = mysql_fetch_array($query);
        $userid = $session['userid'];
    }
   $userid = intval($userid);
   return $userid;
}
Depending on the authentication method used, you can authenticate the user.

Option 1: On-the-fly User Creation Method

No additional code is required (besides that mentioned in the user management section).

Option 2: Restful API User Management Method

If you have created a user using our Restful API, then you can login the user with just chat_id.

<script>
var chat_id = 'LOGGEDIN_USERS_UNIQUE_ID';
</script>
  • Was this helpful?
  • Yes   No