summaryrefslogtreecommitdiff
path: root/includes/helper/session_helper.php
blob: 4063ff69955c58d1280863632a6a06b2340d0416 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
/**
 * Set lifetime of php session.
 *
 * @param int $lifetime
 *          Lifetime in minutes
 * @param string $application_name
 *          Name of the application
 */
function session_lifetime($lifetime, $application_name) {
  // Set session save path and name
  $session_save_path = rtrim(session_save_path(), '/') . '/' . $application_name;
  if (! file_exists($session_save_path))
    mkdir($session_save_path);
  if (file_exists($session_save_path))
    session_save_path($session_save_path);
  session_name($application_name);
  
  // Set session lifetime
  ini_set('session.gc_maxlifetime', $lifetime * 60);
  ini_set('session.gc_probability', 1);
  ini_set('session.gc_divisor', 100);
  
  // Cookie settings (lifetime)
  ini_set('session.cookie_secure', ! (preg_match("/^localhost/", $_SERVER["HTTP_HOST"]) || isset($_GET['debug'])));
  ini_set('session.use_only_cookies', true);
  ini_set('session.cookie_lifetime', $lifetime * 60);
}

?>