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()];
Why can’t you just use the function session_id() ?
I believe I tried and had no success with it. Might be though that I was doing it wrong.
Hi,
How about in drupal 7? It’s working if authenticated user but in anonymous its undefined.
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.