1
Sessions stored in cookies with Login, example
2
======================================
3
(Requires FPC versions past 4/30/2009 /revisions 13062 and later/)
5
Note: Cookies must be enabled for the website in the visitor's browser for it
8
Every visitor needs to log in to get a session ID that is passed in a
9
cookie to the web visitor's browser and stored on the web server until it
11
This way fully functional web sites can be built without mixing the different
14
Note: This example can not distinguish between sessions on the same computer, same
15
browser but different tabs. If for example someone opens three tabs and logs in
16
with all of them, all three browser tabs will be the same session.
17
In order to handle sessions differently by browser tabs the best way to go is
18
to store session IDs in the URLs, Links, etc. for all pages the web application
19
generates (this way cookies are not needed to maintain the session).
20
The sample user logins are stored in userdb.txt for the example.
24
The web server application needs read/write access to the file where the session
25
informations will be stored with the login names (sessiondb.txt by default).
29
Usually it works if you put the templates next to the CGI executable file.
30
(testlogin.html, testlogout.html, testwelcome.html, testsomepage.html and
33
http://<WebServer>/cgi-bin/<CGIExecutableName>/login should start the
34
example if everything is set up properly.
35
ex: http://127.0.0.1:8080/cgi-bin/cookiesession.exe/login
37
Note: You need to change the URLs in the templates if "cgi-bin" or
38
"cookiesession.exe" changes (for example on Linux it is not cookiesession.exe).
44
Usually it works if you put the templates into the Apache main directory (not
45
the DocumentRoot, but the main Apache directory).
46
(testlogin.html, testlogout.html, testwelcome.html, testsomepage.html and
49
http://<WebServer>/<ApacheLocationName>/login should start the
50
example if everything is set up properly.
51
ex: http://127.0.0.1:8080/myapache/login
52
if in httpd.conf it was set up as:
53
LoadModule mod_cookiesession "<path_to_mod>/mod_cookiesession.dll"
55
SetHandler mod_cookiesession
60
Note: You need to change the URLs in the templates if "myapache" changes.
61
Also, for example on Linux the module can be mod_cookiesession.so and not
65
Note: If you recompile an apache module while the module itself is loaded into
66
the Apache server, the compilation will fail because the file is in use (Apache
67
modules stay in the memory). So first you always need to stop the server before
68
you recompile or before you copy over the new version of the created module.
72
(*)To use the same templates for both CGI programs and Apache modules the
73
links can also be generated dynamically when the response html pages are
74
generated. For example instead of putting
76
/cgi-bin/cookiesession.exe/login
79
into the templates, a tag can be used to put the righ link there.
81
<form action="{*SCRIPTPATH*}/login" method="post" ...
82
Of course, the {*SCRIPTPATH*} template tag needs to be replaced with the
b'\\ No newline at end of file'