<-
Apache > HTTP Server > Documentation > Version 2.4 > Modules

Apache Module mod_session_dbd

Available Languages:  en  |  fr 

Description:DBD/SQL based session support
Status:Extension
Module Identifier:session_dbd_module
Source File:mod_session_dbd.c
Compatibility:Available in Apache 2.3 and later

Summary

Warning

The session modules make use of HTTP cookies, and as such can fall victim to Cross Site Scripting attacks, or expose potentially private information to clients. Please ensure that the relevant risks have been taken into account before enabling the session functionality on your server.

This submodule of mod_session provides support for the storage of user sessions within a SQL database using the mod_dbd module.

Sessions can either be anonymous, where the session is keyed by a unique UUID string stored on the browser in a cookie, or per user, where the session is keyed against the userid of the logged in user.

SQL based sessions are hidden from the browser, and so offer a measure of privacy without the need for encryption.

Different webservers within a server farm may choose to share a database, and so share sessions with one another.

For more details on the session interface, see the documentation for the mod_session module.

Support Apache!

Topics

Directives

Bugfix checklist

See also

top

DBD Configuration

Before the mod_session_dbd module can be configured to maintain a session, the mod_dbd module must be configured to make the various database queries available to the server.

There are four queries required to keep a session maintained, to select an existing session, to update an existing session, to insert a new session, and to delete an expired or empty session. These queries are configured as per the example below.

Sample DBD configuration

DBDriver pgsql
DBDParams "dbname=apachesession user=apache password=xxxxx host=localhost"
DBDPrepareSQL "delete from session where key = %s" deletesession
DBDPrepareSQL "update session set value = %s, expiry = %lld, key = %s where key = %s" updatesession
DBDPrepareSQL "insert into session (value, expiry, key) values (%s, %lld, %s)" insertsession
DBDPrepareSQL "select value from session where key = %s and (expiry = 0 or expiry > %lld)" selectsession
DBDPrepareSQL "delete from session where expiry != 0 and expiry < %lld" cleansession
top

Anonymous Sessions

Anonymous sessions are keyed against a unique UUID, and stored on the browser within an HTTP cookie. This method is similar to that used by most application servers to store session information.

To create a simple anonymous session and store it in a postgres database table called apachesession, and save the session ID in a cookie called session, configure the session as follows:

SQL based anonymous session

Session On
SessionDBDCookieName session path=/

For more examples on how the session can be configured to be read from and written to by a CGI application, see the