duanrao3371 2012-08-02 19:58
浏览 53
已采纳

PHP:自定义会话处理程序

just a small question regarding the php session handler, let's say i want to store the session in a database because i have multiple servers that should have access to the session, i would write my own sessionhandler using the interface as described in http://php.net/manual/en/class.sessionhandler.php, but how can i use it? if i do

session_set_save_handler(....);
session_start();
$_SESSION['key'] = 'value';

will it save the data using my handler?

  • 写回答

1条回答 默认 最新

  • duanliaouu965826 2012-08-02 20:11
    关注

    The class that you define and set in set_save_handler() should have all the functions required in the lifetime of a session to be defined. These include read(), write(), destroy() among others.

    Once that is defined correctly you can still manipulate sessions the normal way you do, but in the background, the functions you define will get executed based on which session event you are performing.

    For e.g. $_SESSION['key'] = 'value' will perform the write() function (in which you might have coded a database save routine)

    You can read more about it at: http://us3.php.net/manual/en/function.session-set-save-handler.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端