Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.

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
votes
0answers
28 views

How can i change path of set-cookie in response header in drupal 8

Below is the sample for Set-Cookie of the response header Set-Cookie: SESS624c7ddad7b0526cc343336fe404e237=cCqo-eSoXpZyKoifc1BVSy8PgelrpkSu7QSlCy96JNg; expires=Wed, 11-Dec-2019 15:44:09 GMT; Max-Age=...
0
votes
0answers
26 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 ...
0
votes
0answers
14 views

Keep open state of a block when the page is reloaded

in a search_api view I have several facets links. These links are placed inside several block. If I open a facets block (collapse block), and I click on a facet link the page is reloaded...and the ...
1
vote
0answers
24 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 ...
1
vote
1answer
26 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; $...
0
votes
0answers
11 views

Limit the number of REST sessions per authenticated user

Is there a way through a hook or otherwise to limit the number of concurrent REST sessions an authenticated user can have? I want to be able to limit a user to say no more than five concurrent ...
0
votes
0answers
46 views

User not logged in

I have a Drupal 8 installation and it is not logging in the users. Tried Google search and applied all solutions like setting cookie_domain, trusted_host_patterns and clearing cache. Note that, if ...
0
votes
0answers
29 views

Check for cookie value(s) for a visitor and attempt to authenticate them?

I have a case where when a visitor comes to the site from a subsite (different application), if they are authenticated (there will be a cookie value), I need to get this cookie value and initiate a ...
0
votes
1answer
169 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 ...
0
votes
1answer
43 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. ...
2
votes
1answer
473 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 ...
4
votes
1answer
148 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 ...
1
vote
2answers
179 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->...
0
votes
1answer
303 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 ...
0
votes
2answers
361 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?...
1
vote
0answers
49 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 ...
1
vote
0answers
155 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 ...
0
votes
2answers
601 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 ...
5
votes
1answer
447 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 ...
2
votes
2answers
64 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 ...
1
vote
1answer
320 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 ...
0
votes
0answers
23 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 ...
5
votes
1answer
829 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 ...
0
votes
1answer
1k 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": "...
0
votes
1answer
132 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 ...
0
votes
0answers
113 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-...
0
votes
1answer
362 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 ...
1
vote
1answer
1k 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($...
0
votes
1answer
40 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 ...
0
votes
1answer
229 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\...
0
votes
0answers
195 views

How to make anonymous session data private

I am using this multi-step form example (https://www.sitepoint.com/how-to-build-multi-step-forms-in-drupal-8/ ) for the basis of an online employment application using Drupal 8. All applicants are ...
0
votes
3answers
196 views

Run code when a session ends

Is there a hook or something similar that triggers when a PHP session ends? When a user signs in, I'm writing a few things to the cache, and I need to delete them from the cache when the user exists ...
-1
votes
2answers
96 views

Clear session on checkout complete

I'm using the following code to remember shopping carts per session. The code works just fine, but the problem is that the cart is not emptied on checkout complete, but shows the contents of the ...
1
vote
3answers
213 views

How to implement a button with different redirections?

I'm setting up a job directory using Drupal 8, together with a team. It is possible to see it here. As you can see below, in a screenshot of the site, there's a button called "Add new job": In a ...
4
votes
2answers
2k views

Increase session timeout

So I have a requirement that I'm getting close to stumped on how to complete in Drupal 8. I'm going to attempt to simplify the requirements. I have two roles. They are essentially mutually exclusive. ...
-1
votes
1answer
43 views

Register a custom AttributeBag to the SessionManager

How can I register a new custom AttributeBag into the session manager? I have this custom module and want to contain the session stuff in a specific attributeBag. But when I try to call the ...
1
vote
2answers
40 views

View content based on if a new session is created

I am running a Drupal 7 website using the Ubercart module. I am trying to show some HTML content when users get on the site, and not keep viewing it when they click on a certain button. I need this ...
0
votes
0answers
107 views

Anonymous session data is being carried over for another user

I am saving form values to a session variable for anonymous users in a WebformHandler using the following code: $values = $form_state->getValues(); // set session vars $session = \Drupal::request()...
0
votes
1answer
155 views

How to write session data for another user?

I need to switch to another user, create session for him, write data into the session(his UID), save the session id, then switch back to original user and work with the session id. The account ...
3
votes
0answers
402 views

D8 use Memcache for sessions only

I need to use memcache only for sessions. We have PHP 7.1, php-memcached and Drupal 8 with Memcache module. In session.php we put: $settings['memcache']['servers'] = ['192.168.177.112:11211' => '...
2
votes
1answer
803 views

Reasons for limited login duration?

On a site I am working on, I get logged out almost daily. I assume there is a limit on the login duration. I already set session.gc_maxlifetime to a very high value, using ini_set() in settings.php. ...
1
vote
0answers
443 views

Decoupled session token login issue

I'm new to react and Drupal. I run into the following 403 error in my reactjs login code. I'm using a custom authentication method that I have working, at least using Postman. I also have it working ...
1
vote
1answer
795 views

How to handle session for anonymous users for CSRF tokens?

I need to provide list of CSRF tokens in drupalSettings for every anonymous user so JS can make safe requests to api endpoints. The CSRF service mentions the need for session to exist for the seed ...
2
votes
2answers
157 views

How to change client session variables during a functional browser test?

I have a session variable, that once set changes block output of the system branding block. Normally this variable is intercepted from the query string by an inbound path processor, however that is a ...
0
votes
2answers
103 views

Cannot log in to Drupal running alongside WordPress multi-site

I have a Drupal site (7) that I've migrated to a new server. I have a WordPress multi-site install on this server that looks like this at the moment: example.com store.example.com I used to have a ...
2
votes
2answers
841 views

Restoring tempstore with another session ID

I am building the functionality of sign in during payment checkout in Drupal 8, and I am storing all the values in Drupal 8's tempstore variable. I am capturing the session id for this anonymous user. ...
0
votes
1answer
42 views

Force a session to become HTTPS?

I'm working with a very complex legacy D7 site, and very complex requirements (bleaugh). Anyway: I'm working on a deeplinking system that allows a jump to the site, which then logs-in a user (this is ...
-1
votes
1answer
1k views

Session not refreshing until the cache is cleared

I am trying to store data entered in the drupal custom form in order to display it in next page using session. For the first time it is running perfectly, but for the second time it contains the ...
0
votes
1answer
722 views

How to secure session cookies

I am facing a session cookie hijacking vulnerability please refer the attached image. When i put these cookie in another browser which i simply type the domain like http://example.com and add ...
3
votes
1answer
614 views

When user.private_tempstore gets deleted

I've read about the \Drupal::service('user.private_tempstore')->get('mymodule_name'); and found similar to storing data in $_SESSION. I am using user.private_tempstore in my module to store some ...