IP, .
:
/Config/config.php
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie'] = FALSE;
$config['sess_use_database'] = FALSE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 300;
$config['sess_ignore_ip'] = array('66.249.72.152', '0.0.0.0');
< > //session.php
public function __construct($params = array())
{
log_message('debug', "Session Class Initialized");
$this->CI =& get_instance();
foreach (array('sess_encrypt_cookie', 'sess_use_database', 'sess_table_name', 'sess_expiration', 'sess_expire_on_close', 'sess_match_ip', 'sess_match_useragent', 'sess_cookie_name', 'cookie_path', 'cookie_domain', 'cookie_secure', 'sess_time_to_update', 'time_reference', 'cookie_prefix', 'encryption_key', 'sess_ignore_ip') as $key)
{
$this->$key = (isset($params[$key])) ? $params[$key] : $this->CI->config->item($key);
}
if ($this->encryption_key == '')
{
show_error('In order to use the Session class you are required to set an encryption key in your config file.');
}
$this->CI->load->helper('string');
if ($this->sess_encrypt_cookie == TRUE)
{
$this->CI->load->library('encrypt');
}
if ($this->sess_use_database === TRUE AND $this->sess_table_name != '')
{
$this->CI->load->database();
}
$this->now = $this->_get_time();
if ($this->sess_expiration == 0)
{
$this->sess_expiration = (60*60*24*365*2);
}
$this->sess_cookie_name = $this->cookie_prefix.$this->sess_cookie_name;
$ip_address = $this->CI->input->ip_address();
if(!isset($this->sess_ignore_ip) || empty($this->sess_ignore_ip) || !in_array($ip_address, $this->sess_ignore_ip))
{
if ( ! $this->sess_read())
{
$this->sess_create();
}
else
{
$this->sess_update();
}
}
$this->_flashdata_sweep();
$this->_flashdata_mark();
$this->_sess_gc();
log_message('debug', "Session routines successfully run");
}
function _sess_gc()
{
if ($this->sess_use_database != TRUE)
{
return;
}
srand(time());
if ((rand() % 100) < $this->gc_probability)
{
$expire = $this->now - $this->sess_expiration;
$this->CI->db->where("last_activity < {$expire}");
if(isset($this->sess_ignore_ip) && !empty($this->sess_ignore_ip))
$this->db->where_in('ip_address', $this->sess_ignore_ip);
$this->CI->db->delete($this->sess_table_name);
log_message('debug', 'Session garbage collection performed.');
}
}
IP- .
, , IP- , , , .
, _sess_gc where_in, , IP-, config. , .