Drupal saves its sessions in the sessions table. One can always query they table to get the session ID. There is however a faster way.
If the user is logged it, the session id can be found with the following code:

global $user;
$user->sid;

In any case the session id can also be read from the cookie:

$_COOKIE[session_name()];
§257 · February 25, 2010 · guide, programming, web · Tags: , · [Print]

4 Comments to “Getting session ID in Drupal 6”

  1. Quaoar says:

    Why can’t you just use the function session_id() ?

  2. Darryl says:

    Hi,

    How about in drupal 7? It’s working if authenticated user but in anonymous its undefined.

  3. Kfir says:

    I have to confesse I have yet to work with Drupal 7 and therefore did not test it yet. the $user->sid will definitely not work for anonymous users, but the $cookie should work.

Leave a Reply