Questions tagged [sessions]
Use it for questions about the session system, which handles recognizing users from a session cookie.
234
questions
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', $...
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 ...
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 ...
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 ...
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?
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 ...
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 ...
10
votes
5
answers
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 ...
9
votes
2
answers
1k
views
register.json does not login the user or return the user's session/token/password
I have tried far too many variations to list here, but the basic point is I cannot get the user logged in immediately after registration via Services. I have tried a fresh Drupal 7.33 install with ...
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 ...
8
votes
3
answers
406
views
How can I programatically log another user out in D7?
On our site we have client accounts, each with a super administrator and sub users belonging to that account.
We want the super admin to be able to force sub users to log out. What's the best way to ...
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 ...
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 ...
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 ...
6
votes
4
answers
4k
views
Does user_is_logged_in() check if there is at least one user logged in?
Does the user_is_logged_in() method return TRUE if there is at least one user logged in? Or does it refer to the current session, and returns TRUE if the current user is logged in?
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 ...
5
votes
1
answer
2k
views
How does drupal set user cookie
The following code, let's login any user programmatically.
global $user;
$user = user_load(<any_uid>);
My question is how does the above code triggers to set new user cookies on browser, at ...
5
votes
1
answer
2k
views
How does Drupal verify sessions from the cookie value?
Sorry, I know it's weird, but I'm trying to integrate another php application with Drupal. I want to know if the user is currently logged in to the Drupal site, even though the request is going ...
5
votes
1
answer
6k
views
Session Timeout module [closed]
What's the best module for a session timeout?
I simply want users to be automatically timed out after a period of inactivity.
The Automated Logout module looked like it could to the trick, but it ...
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 ...
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 ...
5
votes
2
answers
4k
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. ...
4
votes
2
answers
712
views
How to prevent multiple logins for administrator?
I have my Drupal website whose admin account is shared. But I want to limit the multiple logins, that is, only one should be able to login at a time. I have already used Session Limit Module. This ...
4
votes
2
answers
8k
views
Session Timeout after certain period of inactivity
How can I logout users after a certain period of inactivity (say 20 minutes)?
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 ...
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 ...
4
votes
2
answers
1k
views
22762 rows in my session table. What does this mean for the site, and what should I do about it?
Ok so the title is pretty self explanatory. There's thousands of rows in the session table. I see that the Persistent Login module is enabled. I don't know if this affects how the sessions are stored. ...
4
votes
2
answers
2k
views
How does the Drupal session system work?
I would like to implement the familiar "Remember me" functionality on user login forms, i.e. if a registered user leaves the browser without hitting the log out link, (s)he will still be logged in ...
4
votes
1
answer
1k
views
Regular session table crashes, on a large multi domain, multi site Drupal set-up
I have recently been assigned to a project that has regular session table crashes.
Drupal outputs an error like this one:
"Warning: Table './[database]/sessions' is marked as crashed and should be ...
4
votes
2
answers
4k
views
How should I share sessions transparently across domains?
I work on a Drupal site which has multiple domains (not sub-domains) using Domain Access to set different themes, display different content, etc. on each of them. These multiple domains are used for ...
4
votes
1
answer
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
5
answers
2k
views
How to keep the size of the database reduced?
I found out a very simple D7 site with less than 150 nodes had database dumps of 65M (gzipped). Which caused my entire server to become slow during the nightly database dumps.
After some searching I ...
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[...
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 ...
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 ...
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', '&...
3
votes
2
answers
820
views
Logging out issue
How can i prevent users who have logged out from accessing their account when they try to access their account by clicking the browser previous-page button?
Currently, users can access their ...
3
votes
1
answer
997
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 ...
3
votes
1
answer
284
views
Drupal sessions in angular app [closed]
I'm developing an angular application which uses drupal as a backend. When user login to my webapp, they can able to get some data from the drupal backend. Also, I'm maintaining a session for that ...
3
votes
2
answers
222
views
Problem with anonymous Flag and webform_select_ options_info() only visible to logged in users
So I've been trying to implement an anonymous "wish list" for an eCommerce site using webform_select_options and Flag. My implementation uses an anonymous flag set on my products and uses ...
3
votes
2
answers
2k
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. ...
3
votes
1
answer
1k
views
How to preserve form values for user who navigates out of form and back?
I have a form that works, essentially, as a search / filter:
foreach($search_properties as $property) {
$form['properties'][$property->idProperty] = array(
'#title' => $property->...
3
votes
2
answers
7k
views
Session variables on custom modules
I have two modules. The first module is for custom login form and the other is for custom user pages.
I want to store a session variable from the first module and later to call on the second module.
...
3
votes
1
answer
257
views
Are there any security concerns with getting the UID by simply querying the sessions table against the visitor's cookie?
In the High Performance JavaScript Callback Handler I'm attempting to use my own code to get the current user's ID.
To give a quick rundown, by returning data at a much lower bootstrap level (...
3
votes
1
answer
526
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 ...
3
votes
0
answers
653
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' =>...
3
votes
1
answer
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 ...
3
votes
3
answers
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
0
answers
838
views
Cookie-less authentication with session ID
I'm building decoupled drupal site. I need to be able to authenticate REST client via session ID passed in a URL (or maybe custom header) instead of a cookie.
At first I thought about implementing my ...
3
votes
1
answer
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 ...