Skip to content
Josaphat Imani nathan edited this page Jul 13, 2023 · 6 revisions

Summary

Cypht supports 3 different session stores out of the box. You can also create your own with the site module set. Remember that after making any changes to your hm3.ini file, you must rerun the scripts/config_gen.php script to update your site configuration. Because session data can contain sensitive data, it is always encrypted regardless of what type of storage is used.

PHP

Standard PHP sessions. This is the default, and is configured in the hm3.ini file by setting session_type to PHP

Database

Database based sessions using a configured PDO compatible database. To use database sessions, you will need to change the session_type value in your hm3.ini file to DB, configure the database in the same file, and create the session table. To configure the database to store sessions, set the following hm3.ini settings for your environment:

Connection type. Can be "host" to connect to a hostname, or "socket" to connect to a unix socket.

db_connection_type=host

Database host name or ip address. If db_connection_type is set to "socket", this value is ignored

db_host=127.0.0.1

If db_connection_type is set to "socket", this should be the filesystem location of the unix socket file. If db_connection_type is set to "host" this value is ignored. ; Memcached Support ; ----------------- ; Cypht can use memcached to cache data. If this enabled, modules that support ; memcache will attempt to use it to improve performance. Currently, only the ; feeds module uses this option. enable_memcached=true memcached_server=127.0.0.1 memcached_port=11211

db_socket=/var/lib/mysqld/mysqld.sock

Name of the database with the required tables

db_name=test

User to connect to the database with

db_user=test

Password to connect to the database with

db_pass=123456

Database type. can be any supported PDO driver ; (http://php.net/manual/en/pdo.drivers.php)

db_driver=mysql

Then create the required table to hold sessions. Mysql/Sqlite and Postgresql examples can be found in the hm3.sample.ini (https://github.com/cypht-org/cypht/blob/master/hm3.sample.ini) file. Here is the Mysql table definition:

CREATE TABLE hm_user_session (hm_id varchar(250), data longblob, date timestamp, primary key (hm_id));

Note that database sessions have no built in way of cleaning up stale sessions (users who don't log out).

Memcached

Cypht can use Memcached to store session data. If Memcached is enabled, other modules will use it to cache data as well. Any sensitive data modules might store in Memcached is encrypted. You must install the Memcached extension to PHP for this to work. To enable Memcached sessions, change the session_type value in the hm3.ini file to MEM, and configure the following options in the same file:

Enable Memcached support enable_memcached=true

Define the Memcached server memcached_server=127.0.0.1

Define the Memcached port memcached_port=11211

Note that Memcached sessions have no built in way of cleaning up stale sessions (users who don't log out).

Custom

You can write your own session handler for Cypht using the site module set. Set the session_type setting in your hm3.ini file to custom, and enable the site module set. Next edit the modules/site/libs.php file: https://github.com/cypht-org/cypht/blob/master/modules/site/lib.php#L101

This file contains a class called Custom_Session which by default extends the PHP based session (though it could extend the Memchached or database sessions as well). It has methods already in place that you can override to provide custom session support.