Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By gosforth on
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
If you are really using
If you are really using Drupal 4.7 it would not work, hook_user_login() is new in Drupal 7
Sorry
, this is 7.x drupal
How are you testing to see if
How are you testing to see if the value is set or not?
I have Drupal test installation
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?
Drupal stores sessions in the
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.
Thanks for explanation
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)?
this is the solution:
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.
Drupal's sessions are more
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.
It's safe to use the Drupal
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:
This will be available in other parts of your code.
I think Drupal
...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.
That only works within the
That only works within the Drupal environment, for example a module or theme.