return 1; } } return 0; } function phpraid_logout() { // unset the session and remove all cookies clear_session(); setcookie('username', '', time() - 2629743); setcookie('password', '', time() - 2629743); } // good ole authentication $lifetime = get_cfg_var("session.gc_maxlifetime"); $temp = session_name("WRM-" . $phpraid_config['auth_type']); $temp = session_set_cookie_params($lifetime, getCookiePath()); session_start(); $_SESSION['name'] = "WRM-" . $phpraid_config['auth_type']; // set session defaults if (!isset($_SESSION['initiated'])) { if (isset($_COOKIE['username']) && isset($_COOKIE['password'])) { $testval = phpraid_login(); if (!$testval) { phpraid_logout(); session_regenerate_id(); $_SESSION['initiated'] = true; $_SESSION['username'] = '******'; $_SESSION['session_logged_in'] = 0; $_SESSION['profile_id'] = -1; } } else {
/** * sets cookie if value is different from current cokkie value, * or removes if value is equal to default * * @uses isHttps() * @uses getCookiePath() * @uses $_COOKIE * @uses CP_removeCookie() * @uses setcookie() * @uses time() * @param string $cookie name of cookie to remove * @param mixed $value new cookie value * @param string $default default value * @param int $validity validity of cookie in seconds (default is one month) * @param bool $httponlt whether cookie is only for HTTP (and not for scripts) * @return boolean result of setcookie() */ function CP_setCookie($cookie, $value, $default = null, $validity = null, $httponly = true) { if ($validity == null) { $validity = 2592000; } if (strlen($value) && null !== $default && $value === $default && isset($_COOKIE[$cookie])) { // remove cookie, default value is used return CP_removeCookie($cookie); } if (!strlen($value) && isset($_COOKIE[$cookie])) { // remove cookie, value is empty return CP_removeCookie($cookie); } if (!isset($_COOKIE[$cookie]) || $_COOKIE[$cookie] !== $value) { // set cookie with new value /* Calculate cookie validity */ if ($validity == 0) { $v = 0; } else { $v = time() + $validity; } /* Use native support for httponly cookies if available */ if (version_compare(PHP_VERSION, '5.2.0', 'ge')) { return setcookie($cookie, $value, $v, getCookiePath(), '', isHttps(), $httponly); } else { return setcookie($cookie, $value, $v, getCookiePath() . ($httponly ? '; HttpOnly' : ''), '', isHttps()); } } // cookie has already $value as value return true; }