--- nfo/site/htdocs/inc/common/common.php.inc 2004/09/01 08:58:40 1.7 +++ nfo/site/htdocs/inc/common/common.php.inc 2004/09/05 06:07:01 1.11 @@ -4,7 +4,7 @@ --- Setup and common functions include file. -------------------------------------------------------------------------------- --- rabit, 04:31 24.08.2004 ---- $Id: common.php.inc,v 1.7 2004/09/01 08:58:40 rabit Exp $ +--- $Id: common.php.inc,v 1.11 2004/09/05 06:07:01 rabit Exp $ ------------------------------------------------------------------------------*/ //------------------------------------------------------------------------------ @@ -102,11 +102,15 @@ //------------------------------------------------------------------------------ //- Session setup: -// Neither proxies, nor the clients are allowed to cache session data: -session_cache_limiter('nocache'); +if(!isset($common['client']['session_enabled'])) { -// This is neccessary to make the $_SESSION global available: -session_start(); + // Neither proxies, nor the clients are allowed to cache session data: + session_cache_limiter('nocache'); + + // This is neccessary to make the $_SESSION global available: + session_start(); + +} common_benchmark_addstep('common: session init'); @@ -121,11 +125,19 @@ 'birthtime' => time(), 'firstrequest' => 1, // Mark the very first page request. - // Empty user data sub array: - 'userdata' => array( + // User data and authorisation: + 'user_auth' => array( 'name' => '', 'password' => '', - 'authorised' => false, + 'authorised' => false + ), + + // User preferences and preferred settings: + 'user_prefs' => array( + 'benchlist' => null, + 'debug' => null, + 'language_id' => null, + 'outputtype' => null ), // Content related additional data: @@ -155,7 +167,7 @@ // Update the request count in the "hits" table: - $sql = "UPDATE hits SET requestcount=requestcount+1 WHERE id='" . $common_sessiondata['hit_id'] . "';"; + $sql = "UPDATE hits SET requestcount=requestcount+1, lastrequest=NOW() WHERE id='" . $common_sessiondata['hit_id'] . "';"; common_dbc_query($sql); @@ -164,22 +176,12 @@ } //------------------------------------------------------------------------------ -//- URL parameter flags and variables: - -if(isset($_GET['devstate'])) $common_sessiondata['userdata']['devstate'] = $_GET['devstate']; - -if(isset($common_sessiondata['userdata']['devstate'])) $common['hostsetup']['devstate'] = $common_sessiondata['userdata']['devstate']; - -//------------------------------------------------------------------------------ //- Functions: -function common_checkauthorisation() { +function common_authorise($username, $password) { global $common_sessiondata; - $username = $common_sessiondata['userdata']['name']; - $password = $common_sessiondata['userdata']['password']; - if((strlen($username) < 2) || (strlen($password) < 2)) return false; $sql = "SELECT id, rights, logincount, lastlogin FROM users WHERE name='$username' AND password='$password';"; @@ -192,6 +194,11 @@ // Congratulations - authorisation suxxessful! + $common_sessiondata['user_auth']['authorised'] = true; + + $common_sessiondata['user_auth']['name'] = $username; + $common_sessiondata['user_auth']['password'] = $password; + $logintime = time(); $userid = $row[0]; @@ -199,19 +206,18 @@ $logincount = $row[2] + 1; $lastlogin = $row[3]; - $common_sessiondata['userdata']['authorised'] = true; - - $common_sessiondata['userdata']['id'] = $userid; - $common_sessiondata['userdata']['lastlogin'] = $lastlogin; - $common_sessiondata['userdata']['rights'] = $rights; + $common_sessiondata['user_auth']['id'] = $userid; + $common_sessiondata['user_auth']['lastlogin'] = $lastlogin; + $common_sessiondata['user_auth']['rights'] = $rights; // Break if the user already has authorised in this session: - if(isset($common_sessiondata['userdata']['logintime'])) return false; + if(isset($common_sessiondata['user_auth']['logintime'])) return false; - $common_sessiondata['userdata']['logincount'] = $logincount; - $common_sessiondata['userdata']['logintime'] = $logintime; + $common_sessiondata['user_auth']['logincount'] = $logincount; + $common_sessiondata['user_auth']['logintime'] = $logintime; -// print_r($common_sessiondata['userdata']); + // Protocol the login: + common_protocollogin(); $sql = "UPDATE users SET logincount='$logincount', lastlogin=FROM_UNIXTIME('$logintime') WHERE id='$userid';"; @@ -236,7 +242,7 @@ $unixtime = $common_sessiondata['birthtime']; $useragent = $_SERVER['HTTP_USER_AGENT']; - $sql = "INSERT INTO hits (id, timestamp, address, entryurl, referer, sessionid, useragent, requestcount) VALUES (NULL, FROM_UNIXTIME('$unixtime'), '$address', '$entryurl', '$referer', '$sessionid', '$useragent', '1');"; + $sql = "INSERT INTO hits (id, timestamp, address, entryurl, referer, sessionid, useragent, requestcount, lastrequest) VALUES (NULL, FROM_UNIXTIME('$unixtime'), '$address', '$entryurl', '$referer', '$sessionid', '$useragent', '1', FROM_UNIXTIME('$unixtime'));"; $res = common_dbc_query($sql); @@ -246,6 +252,25 @@ } +function common_protocollogin() { + +global $common_sessiondata; + + $hitid = $common_sessiondata['hit_id']; + $sessionid = session_id(); + $logintime = $common_sessiondata['user_auth']['logintime']; + $userid = $common_sessiondata['user_auth']['id']; + + $sql = "INSERT INTO logins (id, timestamp, user_id, sessionid, hit_id) VALUES (NULL, FROM_UNIXTIME('$logintime'), '$userid', '$sessionid', '$hitid');"; + + $res = common_dbc_query($sql); + + if(!$res) return false; + + return true; + +} + //---------------------------------------------------------- //- Database functions: @@ -323,7 +348,16 @@ //---------------------------------------------------------- //- File functions: +//---------------------------------------------------------- +//- Utility functions: + +function common_get_baseurl() { +global $common; + + return $common['site']['url']; + +} //------------------------------------------------------------------------------