php - Close session without writing or destroying it -
is there way close php session without either writing or destroying it? missing or there 2 functions (session_write_close()
, session_destroy()
) reset session_status()
php_session_none
? in other words, if have open session, can close without affecting external session data, can reloaded again.
you can $_session = null
. session unavailable data remains (does not deleted).
consider have data in session:
<?php session_start(); session_regenerate_id(); // fresh id echo session_id(); $_session['test'] = '12345'; print_r($_session); // echoes data in session
data: test|s:5:"12345";
then in next request:
<?php session_start(); echo session_id() . "<br>"; // echoes same id of last request $_session = null; print_r($_session); // echoes nothing echo "<br>"; echo session_status(); // echoes 2 (php_session_active)
data still same: test|s:5:"12345";
(php-fpm 5.4.29, recent nginx, memcached session handler
).
well data still can written through $_session['whatever'] = ...
not read. i'm not sure whether solution have admit still don't understand why or whatfor need this.
as alternative, implement wrapper class session property $this->active = true; // or false
:
class mysessionwrapper { protected $active; protected $data; // getter setter $this->active , $this->data ... public function getdata($var) { if ($this->active !== true) { throw new exception('session disabled'); } } }
Comments
Post a Comment