Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CodeIgniter creating a lot of session files #1518

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion application/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@
$config['sess_save_path'] = __DIR__ . '/../../storage/sessions';
$config['sess_match_ip'] = false;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = false;
$config['sess_regenerate_destroy'] = true;

/*
|--------------------------------------------------------------------------
Expand Down
7 changes: 4 additions & 3 deletions system/libraries/Session/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function __construct(array $params = array())
unset($_COOKIE[$this->_config['cookie_name']]);
}

@session_start();
session_start();

// Is session ID auto-regeneration configured? (ignoring ajax requests)
if ((empty($_SERVER['HTTP_X_REQUESTED_WITH']) OR strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) !== 'xmlhttprequest')
Expand All @@ -137,7 +137,7 @@ public function __construct(array $params = array())
}
elseif ($_SESSION['__ci_last_regenerate'] < (time() - $regenerate_time))
{
$this->sess_regenerate((bool) config_item('sess_regenerate_destroy'));
$this->sess_regenerate();
}
}
// Another work-around ... PHP doesn't seem to send the session cookie
Expand Down Expand Up @@ -691,8 +691,9 @@ public function sess_destroy()
* @param bool $destroy Destroy old session data flag
* @return void
*/
public function sess_regenerate($destroy = FALSE)
public function sess_regenerate($destroy = null)
{
$destroy = boolval($destroy !== null ? $destroy : config_item('sess_regenerate_destroy'));
$_SESSION['__ci_last_regenerate'] = time();
session_regenerate_id($destroy);
}
Expand Down