Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is HttpSession implemented?

I just finished taking a final exam on web applications. Capping off what had been a rather easy (albeit lengthy - 12 pages) exam was a question asking us to code an implementation of sessions, similar to that done by javax.http.HttpSession.

I hate to admit, it stumped me. I cranked out a rather BS implemetation using a HashMap and did some craziness with a random cookie string mapping to a serialized HashMap on the server, but I'm pretty sure it's bogus...and now I'm dying to know how it's actually done.

Particularly as someone who has used PHP extensively but for whatever reason never bothered to learn the magic behind the convenience, I'm very interested to learn more about the underlying implementations of sessions. J2EE and PHP for sure, but any other languages/frameworks are great, too. Thanks!

like image 958
Magsol Avatar asked Dec 11 '09 00:12

Magsol


2 Answers

From my understanding - you're close.

From my understanding a cookie with what is essentially an MD5 "ID" is saved on the client side and delivered via cookie or modified GET.

On the server side the "session" data with matched sessionID is saved in a temp file (on Linux it is defaulted to /tmp). The session directory I believe can be set in the PHP.ini file.

like image 190
ChronoFish Avatar answered Oct 13 '22 05:10

ChronoFish


As it is an interface, you may look at the class(es) implementing it in an open-source web container like Tomcat, and see for yourself.

like image 22
Lluis Martinez Avatar answered Oct 13 '22 03:10

Lluis Martinez