I have simple test module with function:

<?php
function current_posts_user_login(&$edit, $account) {
  $_SESSION["something"] = "somevalue";
}

Looks like this piece of code runs when user log in but... session is empty. I do not want to play with Drupal session but want to save php session.

Comments

nevets’s picture

If you are really using Drupal 4.7 it would not work, hook_user_login() is new in Drupal 7

gosforth’s picture

, this is 7.x drupal

nevets’s picture

How are you testing to see if the value is set or not?

gosforth’s picture

on Xampp. I check it in both ways:

- see if there is something in xampp\tmp directory (where xampp stores sessions)
- print_r($_SESSION); or echo $_SESSION["something"]; in some test.php file

Both results gives nothing.
Possible Drupal stores session in another place?

Jaypan’s picture

Drupal stores sessions in the {sessions} table of the database, not as a file.

And calling the Drupal session outside of Drupal will not find the Drupal session.

gosforth’s picture

Hmm... complex interface for trivial thing. I hope it has some sense...
I see session is kept in 'session' field of session table. How to read it outside drupal (avoiding building sql interface and parser)?

gosforth’s picture

<?php
define('DRUPAL_ROOT', 'D:\\xampp\\htdocs\\drupal');
$base_url = 'http://127.0.0.1/drupal'; // THIS IS IMPORTANT
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
global $user;

//echo $user->uid;

echo "<pre>";

print_r($user);

Object 'session' has all logged in user sessions separated by ';'

Works but I do not like it at all - Drupal should just keep sessions as php keeps them.

Jaypan’s picture

Drupal's sessions are more secure, and easier to operate on within the Drupal environment.

You're trying to do stuff outside Drupal - that's where your issues are coming from. It's better to build stuff within Drupal than it is to build external stuff calling Drupal.

Jaypan’s picture

It's safe to use the Drupal session, however you should add a prefix to it for namespacing purposes. I usually use the module name:

$_SESSION['mymodule']['somekey'] = 'some value';

This will be available in other parts of your code.

gosforth’s picture

...does some magical tricks with sessions for some reason in modules and that is why PHP syntax to create session $_SESSION['session'] = "value" will never work.
Tried everything. Save path is correct, is writable, any other script in same directory save session but not Drupal module.

nevets’s picture

That only works within the Drupal environment, for example a module or theme.