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
2
votes
2answers
11k views

How to access session in twig?

I wondering how to access to session in twig ? In my Controller I have this part of code : $tempstore = \Drupal::service('user.private_tempstore')->get('mdm_user'); $tempstore->set('...
0
votes
1answer
27 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 ...
0
votes
2answers
561 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 ...
2
votes
1answer
504 views

Multipage Registration form, Confirmation Page Security Issues?

I have a multipage registration form working on a site, but the confirmation page is supposed to show some of the information (account name and other data) after the account has been submitted/created....
2
votes
1answer
1k views

Using PrivateTempStore for anonymous users with Internal Dynamic Page Cache & Internal Page Cache modules

I'm developing a Drupal 8 project which interacts with an external API. This API handles user authentication, completely bypassing the Drupal user system. This means that logged in API users are ...
0
votes
1answer
755 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 ...
2
votes
1answer
414 views

Twitter sign in module session token values lost in twitter/oauth path in HTTPS - Invalid Twitter OAuth request

The twitter sign in module works on my local and staging server on HTTP fine. But when I install the same module in production mode which is https://example.com, it stops working. The error says "...
2
votes
1answer
1k 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 ...
1
vote
1answer
35 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, ...
0
votes
1answer
2k views

How to set a session variable when a link is clicked?

I have created a search block. It outputs multiple results (names) as links. User can follow the link. How can I pass the user name into $_SESSION variable? I tried doing this, the result shows a page ...
7
votes
2answers
8k 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 ...
3
votes
3answers
3k views

How to add onclick event to a link?

I need to create a link, which when clicked should be able to set a session variable. I have used l() function to create the link and tried this but this is not working. 'name' => l(t($n['name']),...
3
votes
1answer
76 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 ...
4
votes
1answer
1k views

Additional Configuration to disable anonymous session cookies?

I am running a clean install of Pressflow 6.28. I have set the following configurations: Cache Mode: Normal; Min Cache Lifetime: 5 minutes; Page Cache Max Age: 1 day; I have installed no contributed ...
3
votes
1answer
1k views

Is it possible to set Cookie Session ID from a REST Service?

I have overridden Drupal's login process by calling a REST API which returns a 'true' or a 'false' depending on whether the login was successful or not. Once successful, I'm logging the user in by ...
0
votes
1answer
1k 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 ...
10
votes
5answers
5k views

Why are my $messages delayed one page refresh?

I have a page with a very simple template: <!DOCTYPE html> <html> <head><title>TEST REGISTRATION PAGE</title></head> <body> <?php print ...
0
votes
0answers
23 views

Determining unauthenticated user when session cookie exists

We've been experiencing some strange behavior in regards to user sessions that I need help understanding how Drupal determines if a user is authenticated or not. We have a custom endpoint to log in ...
1
vote
0answers
285 views

Autologout on browser close [closed]

I need to log out users when the browser session is closed and users are visiting a Drupal 7 site. I tried to modify the lines on the settings.php which calls ini_set() for session values, but it ...
1
vote
1answer
122 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 ...
17
votes
5answers
23k 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', $...
0
votes
0answers
49 views

Custom Route not reading session cookie to get current user

I'm working on creating custom routes that are meant as an API. So far I have created two routes, 1 to log the user in and another to get the current user. My route file looks like: ytp_user.api.login:...
0
votes
3answers
2k 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?...
3
votes
0answers
570 views

Use Memcache for sessions only [closed]

I need to use memcache only for sessions. We have PHP 7.1, php-memcached, and Drupal 8 with the Memcache module. In session.php we put: $settings['memcache']['servers'] = ['192.168.177.112:11211' =>...
2
votes
3answers
554 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"...
0
votes
1answer
62 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 ...
14
votes
2answers
31k 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 ...
0
votes
1answer
174 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 ...
2
votes
0answers
114 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 ...
2
votes
1answer
60 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 ...
-1
votes
1answer
349 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 ...
0
votes
2answers
3k 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 ...
1
vote
1answer
31 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. ...
0
votes
0answers
62 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 ...
1
vote
1answer
650 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
3answers
937 views

Redirect to page before login

Now i know there are some ways that a redirect on login can be setup, ie using views etc, but i think my issue maybe a bit more complicated. When a user accesses a node for example where they are ...
0
votes
2answers
1k 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 ($...
-2
votes
2answers
174 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 ...
0
votes
0answers
81 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 ...
0
votes
1answer
82 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 ...
2
votes
1answer
195 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; $...
2
votes
1answer
337 views

Hashing function for session

I need to verify the users session of Drupal on a Node.js server. The session ID has been hashed and it is stored in the Drupal 8 database. How can I hash the browsers session ID to compare it with ...
1
vote
1answer
32 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 ...
1
vote
0answers
308 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 ....
0
votes
0answers
56 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()->...
0
votes
0answers
45 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 ...
11
votes
8answers
19k 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?
1
vote
0answers
52 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 ...
4
votes
1answer
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 ...
0
votes
2answers
407 views

How do I access $_SESSION in a view?

Let's say I want to use $_SESSION['user_variable'] with a view as a filter value. I read that in Drupal 7 I could add such a value with custom PHP code. How should I do in Drupal 8? I didn't find an ...

1
2 3 4 5