Back to index

php5  5.3.10
save_handler.inc
Go to the documentation of this file.
00001 <?php
00002 
00003 DEFINE("SESSION_FILE_PREFIX" ,"session_test_");
00004 function open($save_path, $session_name) {
00005     global $session_save_path, $name;
00006     $session_save_path = $save_path;
00007     $name = $session_name;
00008     echo "Open [${session_save_path},${session_name}]\n";
00009     return true;
00010 }
00011 
00012 function close() {
00013     global $session_save_path, $name;
00014     echo "Close [${session_save_path},${name}]\n";
00015     return true;
00016 }
00017 
00018 function read($id) {
00019     global $session_save_path, $name, $session_id;
00020     $session_id = $id;
00021     echo "Read [${session_save_path},${id}]\n";
00022     $session_file = "$session_save_path/".SESSION_FILE_PREFIX.$id;
00023     return (string) @file_get_contents($session_file);
00024 }
00025 
00026 function write($id, $session_data) {
00027     global $session_save_path, $name, $session_id;
00028     $session_id = $id;
00029     echo "Write [${session_save_path},${id},${session_data}]\n";
00030     $session_file = "$session_save_path/".SESSION_FILE_PREFIX.$id;
00031     if ($fp = fopen($session_file, "w")) {
00032         $return = fwrite($fp, $session_data);
00033         fclose($fp);
00034         return $return;
00035     }
00036     return false;
00037 }
00038 
00039 function destroy($id) {
00040     global $session_save_path, $name;
00041     echo "Destroy [${session_save_path},${id}]\n";
00042     $session_file = "$session_save_path/".SESSION_FILE_PREFIX.$id;
00043     return unlink($session_file);
00044 }
00045 
00046 function gc($maxlifetime) {
00047     global $session_save_path, $name;
00048     $directory = opendir($session_save_path."/");
00049     $length = strlen(SESSION_FILE_PREFIX);
00050     while (($file = readdir($directory)) !== FALSE) {
00051         $qualified = ($session_save_path."/".$file); 
00052         if (is_file($qualified) === TRUE) {
00053             if (substr($file, 0, $length) === SESSION_FILE_PREFIX) {
00054                 unlink($qualified);
00055             }
00056         }
00057     }
00058     closedir($directory);
00059     return true;
00060 }
00061 
00062 ?>
00063