Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Python how to take data from another sessionid cookie?

So I'm working with django python, and on every new browser I get a new sessionid for my cookie, every sessionid got a unique session database itself. I'm looking for a way to grab data from other sessionid's if possible.

Example: Im on my site, in 2 different browsers.

Each browser got a unique sessionid cookie, therefore a unique session database.

(cookie examples (not real or valid)):

Chrome: a7363dc Firefox: a3621bcz

In chrome, I got request.session["foo"] Set too "bar"

In Firebox, I got request.session["foo"] set too "zoo"

Is there a way I can like var = request.session[a3621bcz]['foo'] so it takes the value of session "foo" in firefox? (lets say i perform this in chrome)

Or alternatively, is there any way I can make every sessionid cookie the same all the time for everybody? so that everyone has the same access to the request.session["elm"] elements?

Like example: wether im on chrome, firefox, or even at starbucks on my chromebook, when I search for the request.session['foo'] it returns "bar" no matter which one im logging in from?

like image 858
jasonmzx Avatar asked Sep 03 '26 12:09

jasonmzx


1 Answers

You can access the sessions of a given session id with:

from django.conf import settings
from importlib import import_module

engine = import_module(settings.SESSION_ENGINE)
sessionstore = engine.SessionStore

session = sessionstore(session_key)

with session_key the session key (so here 'a3621bcz'). You thus can then access it with session['foo']. That being said, it is probably better not to mix sessions. Django makes use of session middleware to make accessing the relevant session more convenient, and thus prevent "leaking" sessions variables between two sessions.

like image 189
Willem Van Onsem Avatar answered Sep 05 '26 02:09

Willem Van Onsem