Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Managing sessions with C/CGI

Tags:

c

cgi

I'm looking towards writing some applications with C and CGI, and now that I've implemented basic functions like URI encode/decode, HTML entities encode/decode, query/cookie parser, etc. I need to manage sessions. How should I do this? For example, how does PHP manage sessions?

like image 918
Delan Azabani Avatar asked Feb 24 '11 11:02

Delan Azabani


2 Answers

Store the UserID and SessionID in a cookie, then store all other data on the server in a database. Do not encode user and session in the url as this leads to session-hijacking even if the user only wants to show some friend a link.

like image 88
Bernd Elkemann Avatar answered Oct 18 '22 05:10

Bernd Elkemann


As HTTP is stateless, you have to maintain an id that can track your session. The two main ways are to use cookies to store the id or to embed the id in the URL, usually doing URL rewriting.

You can have a look at WT which is a web toolkit written in C++. see also this SO question for a list of c++ web framework. you will probably find how they handle sessions.

my2c

like image 28
neuro Avatar answered Oct 18 '22 05:10

neuro