Sessions

For work with sessions define class Session in the file includes/session.php. The class object is created at the initiation site and is accessible via the variable $this->diafan->_session.

Attention!
The methods of this class are systemic. Their change may cause unstable operation of the entire system.

Свойства

var name – session name.

Example:

echo 'Session name: '.$this->diafan->_session->name;
// output:
// Session name: SESS629188aff6a3c660dc46dedf8724eb61

var id – session ID.

Example:

// use the session as an identifier for the search
// activated online contests for the current user
$coupon_id = DB::query_result("SELECT coupon_id FROM {shop_discount_person}"
." WHERE session_id='%s'", $this->diafan->_session->id);

Методы

void init () – Стартует сессию.

Example:

// start the session
$this->diafan->_session->init();

Functions open, close, read, write, dc, destroy are user session storage functions. They are connected via a PHP-function session_set_save_handler.

boolean true open () – Открывает сессию.

boolean true close () – Закрывает сессию освобождает ресурсы.

string read (string $key) – Читает сессию.

  • string $key: session ID

return true write (string $key, string $value) – Записывает данные в сессию.

  • string $key: session ID
  • string $value: серилизованные данные сессии

void gc () – Чистит мусор - удаляет сессии старше $lifetime.

void destroy ([string $key = '']) – Удаляет ссессию.

  • string $key: session ID

Example:

// delete the session when the user click "Exit"
$this->diafan->_session->destroy();

void duration () – Определяет продолжительность сессии.

Example:

// if the authorization is checked "Do not remember me,"
// the duration of the session, lives up to the closing of the browser window
// Otherwise the session duration is set for a period of 2 weeks
$this->diafan->_session->duration();

By default, session cookies are stored for two weeks.