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
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?
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', $...
17
votes
2answers
25k views

Understanding Drupal's session management and user authentication

I have a requirement where, I have to replace the default user authentication with the authentication of a central server i.e. SSO server. By debugging Drupal I came to know that all the session ...
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 ...
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"...
6
votes
2answers
11k 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 ...
6
votes
1answer
910 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 ...
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 ...
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; $...
20
votes
5answers
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 ...
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 ...
7
votes
3answers
5k 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 ...
5
votes
2answers
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 ...
6
votes
1answer
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 ...
4
votes
1answer
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 ...
3
votes
1answer
998 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 ...
18
votes
4answers
12k 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 ...
3
votes
1answer
2k 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', '&...
1
vote
1answer
2k 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($...
3
votes
2answers
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 ...
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 ...
2
votes
1answer
777 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[...
1
vote
2answers
535 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->...
1
vote
1answer
696 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 ...
1
vote
1answer
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. ...
1
vote
1answer
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'...
0
votes
1answer
378 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
1answer
799 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
2answers
3k 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 ...
0
votes
1answer
191 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/...
-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 ...
-1
votes
2answers
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); ...