Questions tagged [sessions]

Use it for questions about the session system, which handles recognizing users from a session cookie.

Filter by
Sorted by
Tagged with
14 votes
7 answers
23k views

How do I store the values submitted in a form in the session?

I want to submit a form and store the submitted values in the session. In Drupal 7 I just used $_SESSION['key'] = $value; but how do I correctly implement this in Drupal 8?
Robin's user avatar
  • 2,021
20 votes
6 answers
25k views

Storing data / session for anonymous user

I am working on a shop, and for the cart, i need to store items before payment. $tempstore = \Drupal::service('user.private_tempstore')->get('boutique'); $tempstore->set('poids', $...
Kevin's user avatar
  • 2,558
17 votes
2 answers
26k views

Understanding Drupal's session management and user authentication

I have a requirement to replace the default user authentication with the authentication of a central server, i.e., the SSO server. By debugging Drupal, I learned that all the session management ...
AjitS's user avatar
  • 10.9k
11 votes
1 answer
3k views

What is the difference between \Drupal::request()->getSession() and \Drupal::service('user.private_tempstore')?

As the title suggests, I'm a bit confused about those two methods of creating and accessing a session on Drupal 8. I'm not quite sure when to use the one over the other, could someone point me to the ...
user avatar
8 votes
2 answers
9k views

No one can login and access denied message

The site worked till yesterday and just now it's behaving strangely. The site is not created with features, an archive dump including the code and database is copied to server, and the old ...
hkoosha's user avatar
  • 994
7 votes
2 answers
12k views

How to get an anonymous user session id?

I am writing a chat module where anonymous users are able to chat with a logged in user via an external websockets connection. I need an ID to uniquely distinguish the anonymous users and assign them ...
drcelus's user avatar
  • 1,652
2 votes
3 answers
596 views

How to gets analyts and generate visual reports from sessions?

I'm looking for a technique or approach to get data from user session logs and convert it to a some sort of visual style (bars/charts/whatever). We'd like to specifically have the users session "arcs"...
Matt Cocker's user avatar
4 votes
1 answer
2k views

Php Access User Data from external script

Currently my Drupal installation is at www.example.com/wiki/ I was wondering if it is possible in Drupal 8.2.4 to access the current user uid from an external php script. The script is located at ...
user71064's user avatar
2 votes
1 answer
397 views

How to bootstrap a custom script and retrieve the session object?

I'm writing a custom script that requires a proper Drupal 8 user session to work. This is the current version: <?php use Drupal\Core\DrupalKernel; use Symfony\Component\HttpFoundation\Request; $...
Koala Yeung's user avatar
2 votes
1 answer
1k views

How do I dynamically change cookie_lifetime?

I'm trying to change cookie_lifetime dynamically in my D8 project, to set cookie_lifetime to 0 or to some value(for example 24 hours). I know that this can be partially acomplished by changing ...
Артем Ильин's user avatar
20 votes
5 answers
18k views

How do I save session data for the anonymous users?

In my last project for Drupal 6, I did save the data using code similar to the following one: $_SESSION['xxx'] = serialize($data); In Drupal 7, it doesn't work. How should I save the session data ...
vitaly.batonov's user avatar
18 votes
4 answers
14k views

How to logout all active users?

Instead of putting my site in "maintenance mode" I would like to put it in a complete "readonly mode". There is a module for that, however, it only prevents "node add and edit". I would like to ...
uwe's user avatar
  • 12k
14 votes
2 answers
34k views

How to set and retrieve cookies?

After several days and more hours I only found issues and patches about what to do once a cookie is set, but not one is mentioning how you get a cookie set in the first place. Our intention would be ...
Riccardorb's user avatar
7 votes
4 answers
6k views

What is the right way to force a session start?

I'm currently porting SimpleFBConnect module to Drupal 8. This module uses Facebook PHP SDK which expects that we have established a session before the user is redirected to Facebook for ...
Markus Sipilä's user avatar
6 votes
1 answer
2k views

Looking for a hook called before any session is created

I am using Drupal 7 and am looking for a hook which is called before any session is created. According to the the API page, hook_boot() is called after DRUPAL_BOOTSTRAP_SESSION. The link is for ...
rexposadas's user avatar
5 votes
2 answers
4k views

using drupal sessions during hook_boot

When a user calls the front page of our site we want to check the country from which the user is surfing and redirect the user directly to the country specific front page. We chose to use the ...
Matthias's user avatar
  • 163
4 votes
1 answer
6k views

$_SESSION vars created outside of Drupal lost when navigating to a Drupal served page

I'm building a Facebook iframe app in Drupal. I'm using an initial simple PHP script (non-Drupal driven) to handle the Facebook open auth side of things - this script is getting the Facebook user's ...
Steve's user avatar
  • 41
3 votes
1 answer
1k views

Drupal 8 dropping session variables on password reset. Gives 403 Access Denied

I have a fresh install of Drupal 8.6.13, default everything with no custom themes or modules. It was created via: drupal-composer/drupal-project:8.x-dev with the drupal site:new command. When I use ...
user3777203's user avatar
3 votes
1 answer
880 views

Difference between browser session and Drupal session

After reading this question over here from 2014, I'm left wondering: Is there any benefit, security concern, or real reason to use Drupal's session manager class over the browser session $_SESSION[...
gcalex5's user avatar
  • 166
3 votes
2 answers
1k views

Website saves separate sessions for "www.domain.com" and "domain.com"

I open a browser, type "www(dot)mydomain(dot)com" I login as an admin I open a new tab, type "mydomain(dot)com". I'm logged out, and i can login as a different user.. It's weird. I can't find ...
Bibokid's user avatar
  • 325
3 votes
1 answer
3k views

Sessions Table Getting Huge

Currently, my sessions table is 1.6gb with 3,956,161 total rows. I think the sessions does not expired. I have a default settings in my settings.php as follows: ini_set('arg_separator.output', '&...
jaypabs's user avatar
  • 655
1 vote
1 answer
3k views

store session variable and access it through javascript?

In drupal, how do you store/read session variables? Also, how can i access a stored session variable through javascript? I'm trying to store whether if a user has closed my modal or not so it doesn'...
chrisjlee's user avatar
  • 6,540
1 vote
1 answer
3k views

How to access session variables in Twig template?

In a custom module I specified in the hook_preprocess_page function the following session variable: if (isset($blockNameState) && $blockNameState == 'open') { $tempstore->set($...
alexi721's user avatar
1 vote
1 answer
5k views

Post AJAX JSON with session id

Using Drupal Services I am able to log in but each time I post a node it posts as anonymous. I get the session id and session name upon login but can´t pass it along with a POST no matter what i try. ...
MDDY's user avatar
  • 23
1 vote
1 answer
726 views

How do I edit the response of successful register.json?

How can you edit the Services' json response of successful register.json to include the user's OR system's auto-generated password, plus any token? I've tried a variety of combinations of the ...
E.A.T's user avatar
  • 374
1 vote
2 answers
680 views

How to save session data in prod server?

I want to save my data in a session: under drupal 8.6 I worked with "Private tempstore" it works locally but not in the server prod only if user is anonymous. if ($this->currentUser->...
triki hajer's user avatar
0 votes
1 answer
585 views

Site stuck in 'headers have already been sent' login loop after D9 upgrade

Suggestions for debugging a site which is now stuck in a "headers have already been sent" loop after successful login (redirect back to login form)? This is a production server for a site ...
William Turrell's user avatar
0 votes
1 answer
516 views

Drupal 8 reset session each request [closed]

I have create a EventSubscriber like this: <?php namespace Drupal\custom_session\EventSubscriber; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\...
Jonh's user avatar
  • 747
0 votes
1 answer
198 views

user not logged in php file

I want use drupal functions in php files,I did it with below code $path = $_SERVER['DOCUMENT_ROOT']; chdir($path); define('DRUPAL_ROOT', getcwd()); //the most important line require_once './includes/...
Yuseferi's user avatar
  • 21.8k
0 votes
2 answers
4k views

Services 3 Session authentication CSRF Validation with Persistent Log in

I am trying to use Services 7.x-3.11, the latest stable available to authenticate and access Drupal 7.34. Accessing from mobile devices with Native coding. I want to keep the user authenticated ...
niksmac's user avatar
  • 7,682
-1 votes
2 answers
2k views

How to close and start sessions? [closed]

How do i port following D7 code to D8? drupal_save_session(FALSE); session_write_close(); drupal_save_session(TRUE); ini_set('session.cookie_lifetime', $cookie_lifetime); ...
neha's user avatar
  • 662
-1 votes
1 answer
1k views

Get a session value in a template file

I am trying to get value set in session in a template file, but I don't get the expected value. I tried two methods, but neither of them works for me. The code in the custom module controller is the ...
asdsadsa adasdsa's user avatar