PHP 8.3.4 Released!

session_module_name

(PHP 4, PHP 5, PHP 7, PHP 8)

session_module_name現在のセッションモジュールを取得または設定する

説明

session_module_name(?string $module = null): string|false

session_module_name()は、 現在のセッションモジュールの名前を返します。 これは session.save_handler としても知られています。

パラメータ

module

module が指定され、null でない場合、 そのモジュールを代わりに使用します。 このパラメーターに "user" を渡すことは禁止されています。 ユーザー定義のセッションハンドラを設定するには、この関数のかわりに session_set_save_handler() 関数 を呼び出さなければなりません。

戻り値

現在のセッションモジュールの名前を返します。 失敗した場合に false を返します

変更履歴

バージョン 説明
8.0.0 module は、nullable になりました。
7.2.0 モジュール名に "user" を設定することは、 明示的に禁止されるようになりました。 これより前のバージョンでは、 "user" を設定しても静かに無視されていました。
add a note

User Contributed Notes 2 notes

up
5
raees at steelbrain dot com dot pk
9 years ago
This function is used to set the Session Module at site or script level.

The global configuration can be done in php.ini under the [Session] section and with the name of "session.save_handler". The sessions are saved in files by default, like so:
session.save_handler = files

But with this configuration you set one of your websites to use some other session module (if you have them installed and extension loaded with PHP), like so:
<?php

// NOTE: You must use this function before starting session with session_start(); to make it work properly
session_module_name('memcache'); // or pgsql or redis etc

// You'll need to define a save path also, if the module is other than files, like so:
session_save_path('localhost:11211'); // memcache uses port 11211

// or you can use multiple for load balancing:
session_save_path('localhost:11211:41,otherhost:11211:60') // First part is hostname or path to socket, next is port and the last is the weight for that server

//The function also returns the value of the current session module.
echo session_module_name(); // will print memcache in our case

// or maybe a check
if(session_module_name() != 'memcache'){
// Do something, throw an exception maybe
}
up
-2
Anonymous
8 years ago
was looking for a rather comprehensive list of modules, and found http://stackoverflow.com/questions/8415962/what-exactly-phps-function-session-module-name-is-for but there are more.
To Top