From cce1fe9bfea359cebae585eaaa944650bace4966 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Wed, 4 Sep 2013 14:59:34 +0200 Subject: Only store session information for stateful clients Signed-off-by: Florian Pritz --- application/helpers/filebin_helper.php | 15 ++++++++++++++ application/libraries/MY_Session.php | 38 ++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 application/libraries/MY_Session.php diff --git a/application/helpers/filebin_helper.php b/application/helpers/filebin_helper.php index 7ba68b839..53fc4f280 100644 --- a/application/helpers/filebin_helper.php +++ b/application/helpers/filebin_helper.php @@ -356,4 +356,19 @@ function static_storage($key, $value = null) return $storage[$key]; } +function stateful_client() +{ + $CI =& get_instance(); + + if ($CI->input->post("apikey")) { + return false; + } + + if (is_cli_client()) { + return false; + } + + return true; +} + # vim: set noet: diff --git a/application/libraries/MY_Session.php b/application/libraries/MY_Session.php new file mode 100644 index 000000000..0443bca31 --- /dev/null +++ b/application/libraries/MY_Session.php @@ -0,0 +1,38 @@ + + * + * Licensed under AGPLv3 + * (see COPYING for full license text) + * + */ + +class MY_Session extends CI_Session { + private $memory_only = false; + + public function __construct() { + $CI =& get_instance(); + $CI->load->helper("filebin"); + + /* Clients using API keys do not need a persistent session since API keys + * should be sent with each request. This reduces database queries and + * prevents us from sending useless cookies. + */ + if (!stateful_client()) { + $this->memory_only = true; + $CI->config->set_item("sess_use_database", false); + } + + parent::__construct(); + } + + public function _set_cookie($cookie_data = NULL) + { + if ($this->memory_only) { + return; + } + + parent::_set_cookie($cookie_data); + + } +} -- cgit v1.2.3-24-g4f1b