'" . time() . "'"; $db_results = mysql_query($sql, vauth_dbh()); $results = mysql_fetch_assoc($db_results); if (!count($results)) { vauth_error("Query: $sql failed to return results " . mysql_error()); return false; } return $results; } // vauth_get_session /** * vauth_session_cookie * This is seperated into it's own cookie because of some flaws in specific * webservers *cough* IIS *cough* which prevent us from setting at cookie * at the same time as a header redirect. As such on login view a cookie is set */ function vauth_session_cookie() { /* Set the Cookies Paramaters, this is very very important */ $cookie_life = vauth_conf('cookie_life'); $cookie_path = vauth_conf('cookie_path'); $cookie_domain = false; $cookie_secure = vauth_conf('cookkie_secure'); session_set_cookie_params($cookie_life,$cookie_path,$cookie_domain,$cookie_secure); session_name(vauth_conf('session_name')); /* Start the Session */ vauth_ungimp_ie(); session_start(); } // vauth_session_cookie /** * vauth_session_create * This is called when you want to create a new session * It takes care of setting the initial cookie, and inserting the first chunk * of data */ function vauth_session_create($data) { /* function that creates the cookie for us */ vauth_session_cookie(); /* Before a refresh we don't have the cookie, so use session_id() */ $key = session_id(); $username = sql_escape($data['username']); $type = sql_escape($data['type']); $value = sql_escape($data['value']); $expire = sql_escape(time() + vauth_conf('session_length')); /* We can't have null things here people */ if (!strlen($value)) { $value = ' '; } /* Insert the row */ $sql = "INSERT INTO session (`id`,`username`,`type`,`value`,`expire`) " . " VALUES ('$key','$username','$type','$value','$expire')"; $db_results = mysql_query($sql, vauth_dbh()); if (!$db_results) { vauth_error("Session Creation Failed with Query: $sql and " . mysql_error()); } return $db_results; } // vauth_session_create /** * vauth_check_session * This checks for an existing session, and if it's still there starts it and returns true */ function vauth_check_session() { /* Make sure we're still valid */ $session_name = vauth_conf('session_name'); $key = scrub_in($_COOKIE[$session_name]); $results = vauth_get_session($key); if (!is_array($results)) { return false; } /* Check for Rememeber Me */ $cookie_name = vauth_conf('session_name') . "_remember"; if ($_COOKIE[$cookie_name]) { $extended = vauth_conf('remember_length'); vauth_conf(array('cookie_life'=>$extended),1); setcookie($cookie_name, '1', time() + $extended,'/',vauth_conf('cookie_domain')); } /* Set the Cookie Paramaters */ session_set_cookie_params( vauth_conf('cookie_life'), vauth_conf('cookie_path'), vauth_conf('cookie_domain'), vauth_conf('cookie_secure')); /* Set Session name so it knows what cookie to get */ session_name($session_name); vauth_ungimp_ie(); session_start(); return true; } // vauth_check_session /** * vauth_ungimp_ie * This function sets the cache limiting to public if you are running * some flavor of IE. The detection used here is very conservative so feel free * to fix it. This only has to be done if we're rolling HTTPS */ function vauth_ungimp_ie() { if ($_SERVER['HTTPS'] != 'on') { return true; } /* Now try to detect IE */ $agent = trim($_SERVER['HTTP_USER_AGENT']); if ((preg_match('|MSIE ([0-9.]+)|', $agent)) || (preg_match('|Internet Explorer/([0-9.]+)|', $agent))) { session_cache_limiter('public'); } return true; } // vauth_ungimp_ie ?>