63 lines
No EOL
1.1 KiB
PHP
Executable file
63 lines
No EOL
1.1 KiB
PHP
Executable file
<?php
|
|
/**
|
|
* Basic session wrapper / adapter
|
|
*/
|
|
class Session {
|
|
/**
|
|
* Start session
|
|
* @param string $name name of session
|
|
* @param string $path override ini directive session.save_path
|
|
*/
|
|
public static function start($name, $path = null) {
|
|
$started = false;
|
|
if (!$started) {
|
|
session_name($name);
|
|
if ($path !== null) {
|
|
session_save_path($path);
|
|
}
|
|
session_start();
|
|
$started = true;
|
|
}
|
|
Session::setCacheControl('private');
|
|
}
|
|
|
|
/**
|
|
* Set cache control
|
|
* @param string $value sets the http cache control value
|
|
*/
|
|
public static function setCacheControl($value) {
|
|
header('Cache-Control: ' . $value);
|
|
}
|
|
|
|
/**
|
|
* reset session array
|
|
*/
|
|
public static function reset() {
|
|
$_SESSION = array();
|
|
}
|
|
|
|
/**
|
|
* delete client's cookie
|
|
*/
|
|
public static function deleteCookie() {
|
|
if (isset($_COOKIE[session_name()])) {
|
|
setcookie(session_name(), '', time()-42000, '/');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Destroy session completely
|
|
* @return boolean
|
|
*/
|
|
public static function destroy() {
|
|
self::reset();
|
|
self::deleteCookie();
|
|
|
|
if (session_destroy()) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
?>
|