!! Note: Before using this function, you must first configure the php.ini file, Session.save_hadler=user, otherwise, Session_set_save_handler () will not take effect.
In addition, according to my test, if you want to make such a session cross-page use, but also in each session of the script file to add your custom function and Session_set_save_handler, so, the best way is to create a separate file, Include in each script that uses the session.
The following example provides a basic session save method, similar to the default files method.
This is also easy to do if you want to use a database to implement it.
Example 1. Session_set_save_handler () example
$#@60;? Php
function open ($save _path, $session _name) {
Global $sess _save_path, $sess _session_name;
$sess _save_path = $save _path;
$sess _session_name = $session _name;
return (true);
}
function Close () {
return (true);
}
function Read ($id) {
Global $sess _save_path, $sess _session_name;
$sess _file = "$sess _save_path/sess_$id";
if ($fp = @fopen ($sess _file, "R")) {
$sess _data = fread ($fp, FileSize ($sess _file));
Return ($sess _data);
} else {
Return ("");
}
}
function Write ($id, $sess _data) {
Global $sess _save_path, $sess _session_name;
$sess _file = "$sess _save_path/sess_$id";
if ($fp = @fopen ($sess _file, "W")) {
Return (Fwrite ($fp, $sess _data));
} else {
return (false);
}
}
function Destroy ($id) {
Global $sess _save_path, $sess _session_name;
$sess _file = "$sess _save_path/sess_$id";
Return (@unlink ($sess _file));
}
http://www.bkjia.com/PHPjc/532386.html www.bkjia.com true http://www.bkjia.com/PHPjc/532386.html techarticle !! Note: Before using this function, you must first configure the php.ini file, Session.save_hadler=user, otherwise, Session_set_save_handler () will not take effect. In addition, according to my test, if you want to ...