You are here

function flag_set_sid in Flag 7.3

Same name and namespace in other branches
  1. 6.2 flag.module \flag_set_sid()
  2. 7.2 flag.module \flag_set_sid()

Set the Session ID for a user. Utilizes the Session API module.

Creates a Session ID for an anonymous user and returns it. It will always return 0 for registered users.

Parameters

int $uid: (optional) The user ID to create a session ID for. Defaults to the current user.

bool $create: (optional) Determines whether a session should be created if it doesn't exist yet. Defaults to TRUE.

Return value

The session ID, if a session was created. If not, the return value is 0.

See also

flag_get_sid()

1 call to flag_set_sid()
flag_get_sid in ./flag.module
Get the Session ID for a user. Utilizes the Session API module.

File

./flag.module, line 2443
The Flag module.

Code

function flag_set_sid($uid = NULL, $create = TRUE) {
  $sids =& drupal_static(__FUNCTION__, array());
  if (!isset($uid)) {
    $uid = $GLOBALS['user']->uid;
  }

  // Set the sid if none has been set yet. If the caller specified to create an
  // sid and we have an invalid one (-1), create it.
  if (!isset($sids[$uid]) || $sids[$uid] == -1 && $create) {
    if (module_exists('session_api') && session_api_available() && $uid == 0) {

      // This returns one of the following:
      // - -1. This indicates that no session exists and none was created.
      // - A positive integer with the Session ID when it does exist.
      $sids[$uid] = session_api_get_sid($create);
    }
    else {
      $sids[$uid] = 0;
    }
  }

  // Keep the -1 case internal and let the outside world only distinguish two
  // cases: (1) there is an SID; (2) there is no SID (-> 0).
  return $sids[$uid] == -1 ? 0 : $sids[$uid];
}