Questions tagged [session]

A session refers to the communication between a single client and a server. A session is specific to the user and for each user a new session is created to track all the requests from that user.

From Wikipedia:

A session is a semi-permanent interactive information interchange, also known as a dialogue, a conversation or a meeting, between two or more communicating devices, or between a computer and user (see Login session). A session is set up or established at a certain point in time, and torn down at a later point in time. An established communication session may involve more than one message in each direction. A session is typically, but not always, stateful, meaning that at least one of the communicating parts needs to save information about the session history in order to be able to communicate, as opposed to stateless communication, where the communication consists of independent requests with responses.

An established session is the basic requirement to perform a connection-oriented communication. A session also is the basic step to transmit in connectionless communication modes. However any unidirectional transmission does not define a session.

References:

44567 questions
123
votes
5 answers

How to use sessions in an ASP.NET MVC 4 application?

I am new to ASP.NET MVC. I have used PHP before and it was easy to create a session and select user records based on the current session variables. I have looked everywhere on the Internet for a simple step-by-step tutorial that can show me how to…
122
votes
10 answers

What is the proper way to check for null values?

I love the null-coalescing operator because it makes it easy to assign a default value for nullable types. int y = x ?? -1; That's great, except if I need to do something simple with x. For instance, if I want to check Session, then I usually end…
CatDadCode
  • 58,507
  • 61
  • 212
  • 318
122
votes
4 answers

In ASP.NET, when should I use Session.Clear() rather than Session.Abandon()?

Both Session.Clear() and Session.Abandon() get rid of session variables. As I understand it, Abandon() ends the current session, and causes a new session to be created thus causing the End and Start events to fire. It seems preferable to call…
Lance Fisher
  • 25,684
  • 22
  • 96
  • 122
119
votes
3 answers

secret key not set in flask session, using the Flask-Session extension

Right now I am using a flask 3rd party library Flask-Session and I am having no luck getting a session working. When I connect to my site, I get the following error: RuntimeError: the session is unavailable because no secret key was set. Set the…
MintyAnt
  • 2,978
  • 7
  • 25
  • 37
118
votes
10 answers

What is the difference between Session.Abandon() and Session.Clear()

What is the difference between destroying a session and removing its values? Can you please provide an example demonstrating this? I searched for this question, but don't grasp total answer. Some answers are: Session.Abandon() destroys the…
backdoor
  • 1,185
  • 2
  • 8
  • 6
115
votes
10 answers

How to use Session attributes in Spring-mvc

Could you help me write spring mvc style analog of this code? session.setAttribute("name","value"); And how to add an element that is annotated by @ModelAttribute annotation to session and then get access to it?
gstackoverflow
  • 36,709
  • 117
  • 359
  • 710
114
votes
8 answers

Firefox session cookies

Generally speaking, when given a cookie that has no expiration period, modern browsers will consider this cookie to be a 'session cookie', they will remove the cookie at the end of the browsing session (generally when the browser instance…
meandmycode
  • 17,067
  • 9
  • 48
  • 42
114
votes
3 answers

How safe is it to store sessions with Redis?

I'm currently using MySql to store my sessions. It works great, but it is a bit slow. I've been asked to use Redis, but I'm wondering if it is a good idea because I've heard that Redis delays write operations. I'm a bit afraid because sessions need…
Trent
  • 5,785
  • 6
  • 32
  • 43
113
votes
7 answers

How to expire session due to inactivity in Django?

Our Django application has the following session management requirements. Sessions expire when the user closes the browser. Sessions expire after a period of inactivity. Detect when a session expires due to inactivity and display appropriate…
Akbar ibrahim
  • 5,110
  • 3
  • 26
  • 23
111
votes
5 answers

What is default session timeout in ASP.NET?

What is the default session timeout value in ASP.NET?
roushan
108
votes
7 answers

When and why I should use session_regenerate_id()?

Why and when should I use the session_regenerate_id() function in php? Should I always use it after I use the session_start()? I've read that I have to use it to prevent session fixation, is this the only reason?
rvandoni
  • 3,297
  • 4
  • 32
  • 46
108
votes
2 answers

Why is the standard session lifetime 24 minutes (1440 seconds)?

I've been doing some research on PHP Session Handling and came across the session.gc_maxlifetime value of 1440 seconds. I've been wondering why the standard value is 1440 and how it is calculated? What is the basis for this calculation? How long…
Anna Völkl
  • 1,664
  • 2
  • 15
  • 28
107
votes
9 answers

How to find out the request.session sessionid and use it as a variable in Django?

I'm aware that you can get session variables using request.session['variable_name'], but there doesn't seem to be a way to grab the session id(key) as a variable in a similar way. Is this documented anywhere? I can't find it.
rmh
  • 4,806
  • 10
  • 33
  • 31
107
votes
1 answer

What are cookies and sessions, and how do they relate to each other?

I am trying to understand cookies and sessions professionally. I know that when a browser connects to a server, the server "asks" the browser to "paste" a cookie with "phpsessid" in the client browser cookies folder. Now that we have the…
Blanktext
  • 1,528
  • 3
  • 12
  • 17
105
votes
4 answers

How do sessions work in Express.js with Node.js?

Using Express.js, sessions are dead simple. I'm curious how they actually work though. Does it store some cookie on the client? If so, where can I find that cookie? If required, how do I decode it? I basically want to be able to see if a user is…
foobar
  • 10,854
  • 18
  • 58
  • 66