--- nfo/site/htdocs/inc/common/common.php.inc 2004/08/24 03:27:47 1.1 +++ nfo/site/htdocs/inc/common/common.php.inc 2004/09/01 08:58:40 1.7 @@ -4,106 +4,331 @@ --- Setup and common functions include file. -------------------------------------------------------------------------------- --- rabit, 04:31 24.08.2004 ---- $$id$$ +--- $Id: common.php.inc,v 1.7 2004/09/01 08:58:40 rabit Exp $ ------------------------------------------------------------------------------*/ +//------------------------------------------------------------------------------ +//- Benchmarking: + +// Create the benchmark steps array inside "$common": +$common['benchmark'] = array(); + +function common_benchmark_addstep($caption) { + +global $common; + + $step = array($caption, microtime()); + + array_push($common['benchmark'], $step); + +} + +// The starting entry in the benchmark steps list: +common_benchmark_addstep('common: start'); + //---------------------------------------------------------- -//- Developer host setup: +//- Developer host setups: -$cfg['hostsetups'] = array( +$hostsetups = array( 'default' => array( 'urlrel' => '/nfo/', + 'devstate' => false, + 'mysql_host' => 'localhost', + 'mysql_user' => 'nfo', + 'mysql_pass' => 'b2-cV5RF', + 'mysql_db' => 'nfo' ), 'psl.no-ip.com' => array( 'urlrel' => '/work/www.netfrag.org/', + 'devstate' => true, + 'mysql_host' => 'localhost', + 'mysql_user' => 'php', + 'mysql_pass' => 'A289tpQ1', + 'mysql_db' => 'nfo' ), ); -if(isset($cfg['hostsetups'][$_SERVER['SERVER_NAME']])) { +// Set the default host setup: +$common['hostsetup'] = $hostsetups['default']; + +// Set the host setup if a listed host name is given: +if(isset($hostsetups[$_SERVER['SERVER_NAME']])) $common['hostsetup'] = $hostsetups[$_SERVER['SERVER_NAME']]; + +unset($hostsetups); + +common_benchmark_addstep('common: host setup'); + +//---------------------------------------------------------- +//- Site variable setups: + +// Paths: +$common['site']['docroot'] = $_SERVER['DOCUMENT_ROOT'] . $common['hostsetup']['urlrel']; +$common['site']['incroot'] = $common['site']['docroot'] . 'inc/'; +$common['site']['libroot'] = $common['site']['docroot'] . 'libs/'; + +// URLs: +$common['site']['url'] = 'http://' . $_SERVER['HTTP_HOST'] . $common['hostsetup']['urlrel']; +$common['site']['gfxurl'] = $common['site']['url'] . 'gfx/'; + +//---------------------------------------------------------- +//- Page variable setups: + +$common['page']['filename'] = substr($_SERVER['PHP_SELF'], strrpos($_SERVER['PHP_SELF'], '/') + 1); +$common['page']['url'] = $_SERVER['PHP_SELF']; + +common_benchmark_addstep('common: site/page setup'); + +//------------------------------------------------------------------------------ +//- Includes: + +//common_include('cfg/cfg.php.inc'); +//common_benchmark_addstep('common: CFG included'); + +include($common['site']['incroot'] . 'xmlcp/xmlcp.php.inc'); +common_benchmark_addstep('common: XMLCP included'); + +include($common['site']['incroot'] . 'cms/cms.php.inc'); +common_benchmark_addstep('common: CMS included'); + +//------------------------------------------------------------------------------ +//- MySQL connection: + +common_dbc_connectdb(); +common_benchmark_addstep('common: connect database'); + +//------------------------------------------------------------------------------ +//- Session setup: + +// 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'); + +if(!isset($_SESSION['common_sessiondata'])) { + + // The session variable isn't set, create it: + + common_benchmark_addstep('common: New session: start'); + + $common_sessiondata = array( + + 'birthtime' => time(), + 'firstrequest' => 1, // Mark the very first page request. + + // Empty user data sub array: + 'userdata' => array( + 'name' => '', + 'password' => '', + 'authorised' => false, + ), - $cfg['hostsetup'] = $cfg['hostsetups'][$_SERVER['SERVER_NAME']]; + // Content related additional data: + 'additionaldata' => array() + + ); + + common_benchmark_addstep('common: New session: create session'); + + // Protocol the visitors hit and store the columns insertion ID: + $common_sessiondata['hit_id'] = common_protocolhit(); + + common_benchmark_addstep('common: New session: protocol hit'); + + // Store a reference to the session data array: + $_SESSION['common_sessiondata'] = &$common_sessiondata; + + common_benchmark_addstep('common: New session: store session/end'); } else { - $cfg['hostsetup'] = $cfg['hostsetups']['default']; + // Restore the session data array reference: + $common_sessiondata = &$_SESSION['common_sessiondata']; -} + // Reset the first page request flag: + $common_sessiondata['firstrequest'] = null; -$documentroot = $_SERVER['DOCUMENT_ROOT'] . $cfg['hostsetup']['urlrel']; + // Update the request count in the "hits" table: + + $sql = "UPDATE hits SET requestcount=requestcount+1 WHERE id='" . $common_sessiondata['hit_id'] . "';"; + + common_dbc_query($sql); + + common_benchmark_addstep('common: session/hit data updated'); + +} //------------------------------------------------------------------------------ -//- Configuration include file: +//- URL parameter flags and variables: + +if(isset($_GET['devstate'])) $common_sessiondata['userdata']['devstate'] = $_GET['devstate']; -include($documentroot . 'inc/cfg/cfg.php.inc'); +if(isset($common_sessiondata['userdata']['devstate'])) $common['hostsetup']['devstate'] = $common_sessiondata['userdata']['devstate']; //------------------------------------------------------------------------------ //- Functions: -function common_headline($caption) { +function common_checkauthorisation() { - echo '
-(foot notes) -
+ return $common['dbc']['dbconnected']; - +} + +function common_dbc_query($sql) { + +global $common; + + if(!$common['dbc']['dbconnected']) return false; + + $res = mysql_query($sql); + + if($errormsg = mysql_error()) { + + // >>> MTC <<< - + echo $errormsg . '-' . $contents . ' -
-'; +//------------------------------------------------------------------------------ -} +common_benchmark_addstep('common: end'); //------------------------------------------------------------------------------ -?> \ No newline at end of file +?>