I'm still trying to intagrate Drupal with my other non-Drupal scripts and my solutiuons of passing vars through url and forms does not cut it. I need to know how to read Drupal's cookie login. If you could please let me know how to tell if a user is logged in, I'd appreciate the pointer.

Comments

Fusion_Sushi’s picture

So far this is what I've been able to find:

PHPSESSID is the name of the cookie for the session. Each time you login you get a new PHPSESSID but when you log out, your PHPSESSID stays the same, even after closing the browser window. You can get the UID from a query to the sessions table on the PHPSESSID.

I wonder why there is not a difinitive, logged in or logged out field?? does that exist?

moshe weitzman’s picture

$GLOBALS['user'] has all about a user. If that object has a uid > 0, the user is logged in.

dollares’s picture

is it possible to ad and/ or edit some variables of $user?
Are there some functions from drupal?

thanks

newalexandria’s picture

My research suggests (meaning I'm replying from research I've found just now) that data can be appended to a user, permanently, by calling

$user->new_property = $data;
$user_save();

later, calling

$a = $user->new_property;

will assign the saved value to $a

seddonym’s picture

You actually do it like this:


global $user;
user_save($user, array('new_property' => $data));

See http://api.drupal.org/api/function/user_save/6 for more info.

HyperD’s picture

<?php
print_r($_COOKIE['PHPSESSID']);
?>

it doesn't have any contents ... I use Drupal 6.8

itnitwit’s picture

Hi,

I believe PHPSESSID is PHP's default cookie name to store session key. However, Drupal renames this to SESS+md5 hash of the session name (from host domain URL or cookie_domain setting in settings.php file). For example, Drupal.org has SESS2e1f196265529fc19e657f0d379eaed9 for cookie name.

Marc

kbbam’s picture

Drupal7 now uses this rather than md5:

substr(hash('sha256', $cookie_domain), 0, 32)

hypertext200’s picture

It's in configs so you can use

ini_get('session.name')

Heshan Wanigasooriya
Github

davidwhthomas’s picture

You can also return the current session name with:

session_name();

Example

drush @mysite ev 'echo session_name()'
SESS4de2afd5fcb8be4212d8c237be1815c9