Документация PHP


session_set_cookie_params

session_start

Sessions Функции

PHP Manual


session_set_save_handler

(PHP 4, PHP 5)

session_set_save_handler — Sets user-level session storage functions

Описание

bool session_set_save_handler ( callback $open , callback $close , callback $read , callback $write , callback $destroy , callback $gc )

session_set_save_handler() sets the user-level session storage functions which are used for storing and retrieving data associated with a session. This is most useful when a storage method other than those supplied by PHP sessions is preferred. i.e. Storing the session data in a local database.

Список параметров

open

close

read

Read function must return string value always to make save handler work as expected. Return empty string if there is no data to read. Return values from other handlers are converted to boolean expression. TRUE for success, FALSE for failure.

write

Замечание: The "write" handler is not executed until after the output stream is closed. Thus, output from debugging statements in the "write" handler will never be seen in the browser. If debugging output is necessary, it is suggested that the debug output be written to a file instead.

destroy

gc

Возвращаемые значения

Возвращает TRUE в случае успешного завершения или FALSE в случае возникновения ошибки.

Примеры

Пример #1 session_set_save_handler() example

The following example provides file based session storage similar to the PHP sessions default save handler files . This example could easily be extended to cover database storage using your favorite PHP supported database engine.

<?php
function open($save_path$session_name)
{
  global 
$sess_save_path;

  
$sess_save_path $save_path;
  return(
true);
}

function 
close()
{
  return(
true);
}

function 
read($id)
{
  global 
$sess_save_path;

  
$sess_file "$sess_save_path/sess_$id";
  return (string) @
file_get_contents($sess_file);
}

function 
write($id$sess_data)
{
  global 
$sess_save_path;

  
$sess_file "$sess_save_path/sess_$id";
  if (
$fp = @fopen($sess_file"w")) {
    
$return fwrite($fp$sess_data);
    
fclose($fp);
    return 
$return;
  } else {
    return(
false);
  }

}

function 
destroy($id)
{
  global 
$sess_save_path;

  
$sess_file "$sess_save_path/sess_$id";
  return(@
unlink($sess_file));
}

function 
gc($maxlifetime)
{
  global 
$sess_save_path;

  foreach (
glob("$sess_save_path/sess_*") as $filename) {
    if (
filemtime($filename) + $maxlifetime time()) {
      @
unlink($filename);
    }
  }
  return 
true;
}

session_set_save_handler("open""close""read""write""destroy""gc");

session_start();

// proceed to use sessions normally

?>

Примечания

Внимание

As of PHP 5.0.5 the write and close handlers are called after object destruction and therefore cannot use objects or throw exceptions. The object destructors can however use sessions.

It is possible to call session_write_close() from the destructor to solve this chicken and egg problem.

Внимание

Current working directory is changed with some SAPIs if session is closed in the script termination. It is possible to close the session earlier with session_write_close().

Смотрите также


session_set_cookie_params

session_start

Sessions Функции

PHP Manual

SAPE все усложнил?

MainLink - простая и прибыльная продажа ссылок!

Последние поступления:

Размещена 10 августа 2020 года

Я по ТВ видел, что через 10 лет мы будем жить лучше, чем в Германии...
Я не понял, что это они с Германией сделать хотят?!

читать далее…

ТехЗадание на Землю

Размещена 14 марта 2018 года

Пpоект Genesis (из коpпоpативной пеpеписки)

читать далее…

Шпаргалка по работе с Vim

Размещена 05 декабря 2017 года

Vim довольно мощный редактор, но работа с ним не всегда наглядна.
Например если нужно отредактировать какой-то файл например при помощи crontab, без знания специфики работы с viv никак.

читать далее…

Ошибка: Error: Cannot find a valid baseurl for repo

Размещена 13 сентабря 2017 года

Если возникает ошибка на centos 5 вида
YumRepo Error: All mirror URLs are not using ftp, http[s] or file.
Eg. Invalid release/

читать далее…

Linux Optimization

Размещена 30 июля 2012 года

Prelink

читать далее…