namespace infrajs\infra; use infrajs\access\Access; use infrajs\event\Event; use infrajs\ans\Ans; use infrajs\path\Path; use infrajs\session\Session; if (!is_file('vendor/autoload.php')) { chdir(explode('vendor/', __DIR__)[0]); require_once 'vendor/autoload.php'; } Access::admin(true); $ans = array(); if (isset($_GET['get'])) { $name = Ans::REQ('name'); $ans['id'] = Session::getId(); $ans['data'] = Session::get($name); } else { if (isset($_GET['clear'])) { Session::clear(); } else { if (isset($_GET['set'])) { $ans = array(); $name = Path::toutf($_REQUEST['name']); $val = Path::toutf($_REQUEST['val']); Session::set($name, $val); } } } return Ans::ret($ans);
public static function writeNews($list, $session_id) { if (!$list) { return; } $db =& Db::pdo(); global $infra_session_lasttime; $isphp = !!$infra_session_lasttime; $sql = 'insert into `ses_records`(`session_id`, `name`, `value`, `time`) VALUES(?,?,?,FROM_UNIXTIME(?))'; $stmt = $db->prepare($sql); $sql = 'delete from `ses_records` where `session_id`=? and `name`=? and `time`<=FROM_UNIXTIME(?)'; $delstmt = $db->prepare($sql); Each::exec($list, function &($rec) use($isphp, &$delstmt, &$stmt, $session_id) { $r = null; if (!$isphp && $rec['name'][0] == 'safe') { return $r; } $name = Sequence::short($rec['name']); $delstmt->execute(array($session_id, $name, $rec['time'])); $stmt->execute(array($session_id, $name, Load::json_encode($rec['value']), $rec['time'])); if (!$isphp && !$name) { //Сохранится safe Session::clear(); } return $r; }); }