You are here

function drupalchat_get_current_guest_id in DrupalChat 7

2 calls to drupalchat_get_current_guest_id()
drupalchat_get_current_guest_name in ./drupalchat.module
_drupalchat_get_sid in ./drupalchat.module

File

./drupalchat.module, line 1456
Module code for DrupalChat.

Code

function drupalchat_get_current_guest_id() {
  if (isset($_SESSION) && isset($_SESSION['drupalchat_guest_id'])) {

    //if(!isset($_COOKIE) || !isset($_COOKIE['drupalchat_guest_id'])) {
    setrawcookie('drupalchat_guest_id', rawurlencode($_SESSION['drupalchat_guest_id']), time() + 60 * 60 * 24 * 365);
    setrawcookie('drupalchat_guest_session', rawurlencode($_SESSION['drupalchat_guest_session']), time() + 60 * 60 * 24 * 365);

    //}
  }
  else {
    if (isset($_COOKIE) && isset($_COOKIE['drupalchat_guest_id']) && isset($_COOKIE['drupalchat_guest_session']) && $_COOKIE['drupalchat_guest_session'] == drupalchat_compute_guest_session($_COOKIE['drupalchat_guest_id'])) {
      $_SESSION['drupalchat_guest_id'] = check_plain($_COOKIE['drupalchat_guest_id']);
      $_SESSION['drupalchat_guest_session'] = check_plain($_COOKIE['drupalchat_guest_session']);
    }
    else {
      $characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
      $drupalchatId = time();
      for ($i = 0; $i < 5; $i++) {
        $drupalchatId .= $characters[rand(0, strlen($characters) - 1)];
      }
      $_SESSION['drupalchat_guest_id'] = $drupalchatId;
      $_SESSION['drupalchat_guest_session'] = drupalchat_compute_guest_session($_SESSION['drupalchat_guest_id']);
      setrawcookie('drupalchat_guest_id', rawurlencode($_SESSION['drupalchat_guest_id']), time() + 60 * 60 * 24 * 365);
      setrawcookie('drupalchat_guest_session', rawurlencode($_SESSION['drupalchat_guest_session']), time() + 60 * 60 * 24 * 365);
    }
  }
  return $_SESSION['drupalchat_guest_id'];
}