<?php
/*
There are two ways to use this session handler:
1. Replace the session_start() with include "session_handler.php" - this will create your application have the same session as zencart (for admin section integration you need to change the $session_name from zenid to zenAdminID
2. Call it in html as an image (<img src='session_handler_img.php' alt="">) - this will only help you to keep the zencart session alive and you should be keeping your session timeout to 24 minutes which is the zencart session timeout standard time (hardcoded).
*/
//open zencart class first
require_once("zencart.class.php");
function zencart_sess_open($save_path, $session_name) {
return true;
}
function zencart_sess_close() {
return true;
}
function zencart_sess_read($session_id) {
global $session_lifetime, $session_read, $zencart_path;
$tmp_zc = new zencart($zencart_path);
if($session_read = $tmp_zc->q_fetch(false, "SELECT * FROM ".$tmp_zc->cfg_params["DB_PREFIX"]."sessions WHERE sesskey = '$session_id' AND expiry > " . time()))
return $session_read['value'];
else
return '';
}
function zencart_sess_write($session_id, $session_data) {
if (!$session_data) return FALSE;
global $session_lifetime, $session_read, $zencart_path;
$tmp_zc = new zencart($zencart_path);
$expiry = time() + $session_lifetime;
$_session_data = $tmp_zc->db_sanitize($session_data);
if($session_read)
$result = $tmp_zc->query("UPDATE ".$tmp_zc->cfg_params["DB_PREFIX"]."sessions SET expiry = $expiry, value = '$_session_data' WHERE sesskey = '$session_id' AND expiry > " . time());
else{
//$result = $tmp_zc->query("DELETE FROM ".$tmp_zc->cfg_params["DB_PREFIX"]."sessions WHERE sesskey = '$session_id'");
$result = $tmp_zc->query("INSERT INTO ".$tmp_zc->cfg_params["DB_PREFIX"]."sessions VALUES ('$session_id', $expiry, '$_session_data')");
}
return TRUE;
}
function zencart_sess_destroy($session_id) {
global $zencart_path;
$tmp_zc = new zencart($zencart_path);
$result = $tmp_zc->query("DELETE FROM ".$tmp_zc->cfg_params["DB_PREFIX"]."sessions WHERE sesskey = '$session_id'");
return TRUE;
}
function zencart_sess_gc($session_lifetime) {
global $zencart_path;
$tmp_zc = new zencart($zencart_path);
$query = "DELETE FROM ".$tmp_zc->cfg_params["DB_PREFIX"]."sessions WHERE expiry < " . time();
$result = $tmp_zc->query($query);
return mysql_affected_rows();
}
session_set_save_handler("zencart_sess_open", "zencart_sess_close", "zencart_sess_read", "zencart_sess_write", "zencart_sess_destroy", "zencart_sess_gc");
ini_set("session.save_handler", "user" );
$zencart_path = dirname(dirname(dirname(__FILE__)))."/zencart/";
$session_cookie_lifetime = 0;
$session_cookie_path = '/';
$session_cookie_domain = '';
$session_cache_expire = 60 * 24 * 30;
//$session_lifetime = ini_get("session.gc_maxlifetime");
$session_lifetime = 60 * 24 * 30;
$session_name = "zenid";
session_name($session_name);
$session_cookie_secure = @$_SERVER["HTTPS"] == "on"?true:false;
session_set_cookie_params($session_cookie_lifetime, $session_cookie_path, $session_cookie_domain, $session_cookie_secure);
//if(version_compare(phpversion(), "4.3.0", ">=")) ini_set("session.use_only_cookies", $session_use_only_cookies);
if(version_compare(phpversion(), "4.2.0", ">=")) session_cache_expire($session_cache_expire);
ini_set("session.url_rewriter.tags", 'a=href,area=href,frame=src,input=src,form=fakeentry');
session_start();
?>
|