Skip to main content

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
1 vote
1 answer
274 views

Using a session for anonymous users

I set some session data for a user I auto logged out. Then tried to retrieve that session data in a form validation. It is not there. class MFAController extends ControllerBase { public function ...
Donald Winston's user avatar
0 votes
0 answers
39 views

Can't access the $_SESSION array from within custom module

I m beginner on drupal, and i have a problem with session. I created a custom form submission inside the clubs module. namespace Drupal\idan_login\Form; // Form submission handler. public function ...
Mohamed Ouhammou's user avatar
3 votes
1 answer
68 views

Drupal unable to login and logout several accounts in a single functional test

I am trying to run some functional tests in DDEV that check functions of protected routes. I can log in the first couple of users fine, but after that drupaLogin() fails to generate a logged in ...
Kevin's user avatar
  • 27.9k
0 votes
0 answers
54 views

TFA Session expired when user login

not sure if anyone faces this issue, when I tried to login with the authentication. It shows TFA session has expired. But the user account was logged in. Screenshot attached, I tried to drupal set ...
DevNooby's user avatar
0 votes
0 answers
212 views

Messenger doesn't display value after user logged out and redirect

After my user is submitting a form, I want to logged him out, then redirect to the front page. then, display a message. public function submitForm(array &$form, FormStateInterface $form_state) { ...
lobafox's user avatar
  • 123
1 vote
1 answer
474 views

Persistent anonymous user session with headless D9

In short: a new php session is started upon every request made through nextjs, I somehow must keep the anonymous user session alive. For my anonymous users I need keep track of data submitted through ...
Maarten Hartman's user avatar
0 votes
0 answers
86 views

Login fails: returns to anonymous user home page with no message

I am testing upgrade to Drupal 9. I upgraded core and logged in and fixed a few issues with module deprecated code and then was presented with a Twig issue where replace syntax had changed. I changed ...
Mark Edwards's user avatar
0 votes
1 answer
707 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
3 votes
1 answer
597 views

Can I use the session service directly instead of via the request?

The Drupal documentation on sessions mentions that sessions can be accessed via the Request object: Session data is accessed via the \Symfony\Component\HttpFoundation\Request::getSession() method, ...
Neograph734's user avatar
  • 8,429
3 votes
1 answer
612 views

Is there an event related to the creation of a session cookie for anonymous users?

I need to set an additional cookie whenever an anonymous user received a session cookie. This happens when selecting a facet in Search API for example. The specific use case is that I need an extra ...
Sean Robertson's user avatar
1 vote
1 answer
344 views

Token Replacement via Lazy_builder

I've spent the best part of the last day or two trying to implement lazy_builder (as seen in this brilliant tutorial https://github.com/joachim-n/drupalcon-europe-2020-lazy-builders). However, rather ...
Adamation's user avatar
0 votes
1 answer
83 views

Callback to Drupal site after curl call to 3rd party site doesn't resume authenticated session if more than 120 seconds elapsed since authentication

UPDATED SITUATION: A user authenticates on my site. The user selects items to purchase and is sent via curl call (see below) to a payment site. The payment site does its thing and returns to my site ...
Marshall Morrise's user avatar
0 votes
1 answer
1k views

Private tempstore storage contains data for previous anonymous user

I have an issue with private tempstore storage that I wasn't able to solve. I've implemented a webform handler, which populates data in this storage and then I'm creating tokens out of the saved ...
Miloš Kroulík's user avatar
2 votes
0 answers
271 views

Session variable and cache drupal [closed]

I've created a small helper where I can set and access my session variable (thanks to the drupal 8 session). Can't figure out why, my session is working well with my dev (no cache) but on my prod my ...
lucrece's user avatar
  • 21
2 votes
1 answer
180 views

Using an authentication provider to keep a user permanently logged in eventually causes session problems

Because I got fed up of having to log in to my local development sites every however long, I tried making a simple custom module that just has an Authentication Provider service that always returns ...
joachim's user avatar
  • 846
-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
1 vote
1 answer
109 views

Why are there entries in sessions table for uid 0?

I was alarmed to find sessions being written to the table [sessions] for uid 0. Do I need to worry or is this normal? I could not find answers by searching. I don't know how the sessions table works. ...
Edward Peters's user avatar
0 votes
0 answers
67 views

Set and read data in session between anonymous and authenticated user [duplicate]

On my Drupal 8 site, when an anonymous user "A" visit this link: https://www.example.com/page-1?data=12345678, I want to store the data value in a session and save it later to the user account under ...
Vanessa Abi Rashed's user avatar
0 votes
2 answers
2k views

Why 'Failed to start the session' when RedirectResponse is sent?

When this code is executed, I have an error message logged. The code is in shared_node_access(NodeInterface $node, $op, AccountInterface $account) if ($node->get('nid')->value == 1) { if ($...
gbmapo's user avatar
  • 1,086
-2 votes
2 answers
328 views

Incorrect handling of PHP sessions causes many 503 errors?

I use my personal website to host several images galleries, and for several months now, I've noticed that a lot of the thumbnail images appear broken and aren't loaded by the browser. This seems to be ...
s427's user avatar
  • 735
0 votes
0 answers
193 views

SESSxxxxx cookie gets removed, $_SESSION data being lost but only locally

I have just pulled deployed code down to my local setup, restarted MAMP, cleared the Drush cache, and started a process that relies on data stored in $_SESSION. We can confirm this works in prod - no ...
Vincent Buscarello's user avatar
0 votes
1 answer
102 views

How do I troubleshoot PrivateTempStore for session data?

I am updated one of my Drupal 7 modules for Drupal 8 and I discovered that I need to use PrivateTempStore rather than $_SESSION variables. I followed some great examples online, but it does not seem ...
shelane's user avatar
  • 511
1 vote
1 answer
102 views

Service to interface with sessions table?

In my module, I need greater session control, beyond simple max_lifetime and other parameters taken from PHP config. What I did was to add a column to the sessions table that gives me the effective ...
Ynhockey's user avatar
  • 430
1 vote
0 answers
782 views

cant read current user in middleware

i am relatively new to drupal . thus i am trying to make an sso system work . i have this parent domain "domain.com" and the drupal site is running on sub.domain.com  . i can read the cookies and all ....
akramabdelrahman's user avatar
0 votes
0 answers
194 views

How do change the value of a session before form submission

I created a custom module that allows users to enter their information, and during the form submission, I set a session with the name that they type in the form: $session = \Drupal::request()->...
Sidney Sousa's user avatar
0 votes
0 answers
92 views

How do I get rid of anonymous sessions?

In a Drupal 7 site taken over from an ex-colleague, sessions for anonymous user always are generated as this screenshot shows. The security-scanning service provider always claims: Our ...
Vincent's user avatar
1 vote
0 answers
219 views

Is it possible to provide a temporary role to an anonymous session?

Use-case is to provide a set of permissions to an "anonymous" user i.e. we don't know who they are and they haven't logged in, we just have their IP range to confirm where they're coming from (yes I ...
Eli Lisseck's user avatar
2 votes
1 answer
415 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
2k 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
0 votes
1 answer
64 views

session_unset logs out user when viewing the page

We have an application that we developed in Drupal 7 and I am tasked with migrating this form to Drupal 8. I have a question about the session behavior which seems to have changed from Drupal 7 to 8. ...
Chris Howell's user avatar
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
12 votes
1 answer
4k 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
1 vote
2 answers
724 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
1 vote
1 answer
2k views

SSESS Cookie (Session ID) is being changed when loading images that don't exist

I have a Drupal 8.6.10 site which has a very confusing logout bug: I have a page that has various elements on it as images, js, css and so on. I load that page and everything works fine I add an ...
Florian Müller's user avatar
0 votes
3 answers
3k views

How do I display username in a custom block?

Am new to Drupal so this is a very fundemental question. How do I display the current username ? In a custom Block? I beleive is the $user->name session variable. Do I create a Custom Block Type?...
Kickaha's user avatar
  • 123
1 vote
0 answers
73 views

update all active sessions with custom data stored in the database sessions

Every user stores the session-data in the database (xxx_sessions). The tricky thing here is a custom data stored in the session with $_SESSION['CURRENT_DOC_YEAR'] = $current_doc_year;. This session ...
Criss's user avatar
  • 11
1 vote
0 answers
317 views

Same session variable retrieved in different blocks not stable

I have a module that have three blocks. Block No 1 sets the session Block No 2 gets the session Block No 3 remove the session Each block is assigned to a different page. Now, for some reason this ...
DavSev's user avatar
  • 153
1 vote
2 answers
4k views

Is it possible to unset private_tempstore values?

I have a block that creates a private_tempstore value (which I understand works exactly like PHP sessions). How do I unset that value. This is the code I am using for the block. class ...
DavSev's user avatar
  • 153
5 votes
1 answer
1k views

How does core triggers cleanup of expired sessions in database?

core/lib/Drupal/Core/Session/SessionHandler.php defines a method (gc()) to clear expired sessions from the database (sessions table) when is that triggered ? is there a way to trigger it from the ...
izus's user avatar
  • 1,132
2 votes
2 answers
130 views

Force redirect back to password form until password got set after one-time-login

When my users click on a one-time-password-reset link then I log them in and then show them a page where they can choose their new password. Problem is that there are two additional links on that page ...
Pawan's user avatar
  • 123
1 vote
1 answer
1k views

Switch user session programmatically

I'm trying to switch user session thanks to Drupal Switch. I want to do this so that when I have a certain role, I can switch to another user account to check some data from the user i choose to ...
Morgan Tartreau's user avatar
0 votes
0 answers
28 views

How to hit an endpoint (menu route) with the session intact

I'm trying to hit an endpoint which shows different data when logged in/out. I am trying to write a unit test, but can't seem to figure out how to hit the end point with user context. How can I do ...
user1015214's user avatar
  • 1,811
7 votes
1 answer
5k views

What is the difference between a Drupal session variable and a cookie?

When you set a Drupal session variable (i.e. a "magic" variable you may set like this): $_SESSION['mymodule'] = array('key' => 'value'); the value goes away when the user logs out. If you set a ...
Free Radical's user avatar
  • 15.1k
2 votes
1 answer
3k views

Rest login cookie token explanation

When logging in via a POST to user/login?_format=json I'm sent back a response that looks like this { "current_user": { "uid": "233", "name": "test" }, "csrf_token": "...
Shawn Matthews's user avatar
0 votes
2 answers
2k views

How do I keep data without using sessions

Is there a way to store data for separate users in Drupal without using sessions. I have previously used Drupal varibales. But it didin't work because the variable gets updated for every user (So ...
i am batman's user avatar
0 votes
0 answers
280 views

Session Fails to Start

In my drupal site, it has been working fine for a while, but recently users have not been able to log in to the site (including me as admin). I am seeing the following error in my php logs: [28-Jul-...
atg963's user avatar
  • 63
0 votes
1 answer
978 views

Access denied for all users, sessions table empty, access log shows NULL uid

My Drupal 7 site has been up and running for a couple years without issue. I went to log in as admin today to check for security updates and had the following experience: When I first browse to the ...
Thomas's user avatar
  • 101
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
0 votes
1 answer
158 views

Is a session alone enough for non logged-in users to see some information?

In my project I have a content type called Person that is only viewable or editable by logged-in user. In this content type, I added some fields. I want to give a person the ability to visit his ...
Mehrdad201's user avatar
  • 1,312
0 votes
1 answer
538 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
  • 777

1
2 3 4 5