Commit 06c8e222 authored by thejoelinux's avatar thejoelinux

param sessions saas

parent decf72d2
......@@ -13,7 +13,7 @@ spl_autoload_register("myautoload");
include("config/config.php");
global $data;
$data = new data();
$session_db = new session_db();
new session_saas();
global $logged_user;
$logged_user = new User(0);
if(!array_key_exists("user_id", $_SESSION)) {
......
<?php
// This class store/retrieve the sessions in/from the database.
// You will need this if you have more than one webserver
// to enable the persistence of sessions accross different front servers.
class session_saas extends data {
private $life_time = 0;
public function __construct() {
// DEBUG trigger_error('session_db::__construct called', E_USER_NOTICE);
session_set_save_handler(
array(&$this, 'open'),
array(&$this, 'close'),
array(&$this, 'read'),
array(&$this, 'write'),
array(&$this, 'destroy'),
array(&$this, 'gc')
);
// session_name("whatever");
$this->life_time = ini_get('session.gc_maxlifetime');
// -- Define a lifetime on session cookie
if ( ini_get('session.use_only_cookies') == 1 && intval($this->life_time)>0 ) {
ini_set('session.cookie_secure', FALSE);
ini_set('session.cookie_httponly', TRUE);
session_set_cookie_params($this->life_time);
}
session_start();
}
public function __destruct() {
// DEBUG trigger_error('session_db::__destruct called', E_USER_NOTICE);
}
public function open() {
// DEBUG trigger_error('session_db::open called', E_USER_NOTICE);
// -- Maintain session cookie updated for each requests
if ( ini_get('session.use_only_cookies')==1 && intval($this->life_time)>0 ) {
setcookie(session_name(),session_id(),(time()+$this->life_time), '/');
}
return true;
}
public function close() {
// DEBUG trigger_error('session_db::close called', E_USER_NOTICE);
$this->gc($this->life_time);
return true;
}
public function read($id) {
// DEBUG trigger_error('session_db::read called', E_USER_NOTICE);
$session = json_decode(file_get_contents($GLOBALS["saas_auth_url"].
"?o=saas_sessions&a=read&i=".$id));
return base64_decode($session->data);
}
public function write($id, $data) {
// DEBUG trigger_error('session_db::write called', E_USER_NOTICE);
$postdata = http_build_query(
array(
'o' => 'saas_sessions',
'a' => 'write',
'i' => $id,
'data' => base64_encode($data)
)
);
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$context = stream_context_create($opts);
return json_decode(file_get_contents($GLOBALS["saas_auth_url"], false, $context));
}
public function destroy($id, $key_only = FALSE) {
// DEBUG trigger_error('session_db::destroy called', E_USER_NOTICE);
$postdata = http_build_query(
array(
'o' => 'saas_sessions',
'a' => 'destroy',
'i' => $id
)
);
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$context = stream_context_create($opts);
return json_decode(file_get_contents($GLOBALS["saas_auth_url"], false, $context));
}
public function gc($max) {
// DEBUG trigger_error('session_db::gc called', E_USER_NOTICE);
return json_decode(file_get_contents($GLOBALS["saas_auth_url"].
"?o=saas_sessions&a=gc"));
}
}
......@@ -13,7 +13,9 @@ spl_autoload_register("myautoload");
include("config/config.php");
global $data;
$data = new data();
$session_db = new session_db();
//$session_db = new session_db();
new session_saas();
global $logged_user;
$logged_user = new User(0);
if(!array_key_exists("user_id", $_SESSION)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment