You are here

function session_api_get_sid in Session API 5

Same name and namespace in other branches
  1. 6 session_api.module \session_api_get_sid()
  2. 7 session_api.module \session_api_get_sid()

Return a Session API ID corresponding to the current session. The Session API ID is the mapping of the private php session_id [1] to the ID used by modules leveraging the Session API.

1. http://php.net/manual/en/function.session-id.php

1 call to session_api_get_sid()
SessionApiTestCase::testFunctions in tests/session_api.test
Verify functions.

File

./session_api.module, line 24
The Session API module provides a quick interface for storing information in the session.

Code

function session_api_get_sid() {
  if (!session_api_available()) {
    return FALSE;
  }
  if (!is_numeric($_SESSION['session_api_id'])) {

    // first, check if id exists in db
    $sid = db_result(db_query("SELECT sid FROM {session_api} WHERE session_id = '%s'", session_id()));
    if (!$sid) {

      // no sid exists, create new one
      $sid = db_next_id('{session_api}_sid');
      db_query("INSERT INTO {session_api} (sid, session_id) VALUES (%d, '%s')", $sid, session_id());
    }
    $_SESSION['session_api_id'] = $sid;
  }
  return $_SESSION['session_api_id'];
}