Difference between revisions of "Including lib-common.php"

From GeeklogWiki
Jump to: navigation, search
(Short article on how to properly include lib-common.php and why)
 
m
Line 11: Line 11:
 
* '''or use a relative path''', i.e.
 
* '''or use a relative path''', i.e.
 
:../../lib-common.php
 
:../../lib-common.php
* '''never(!)''' use a variable in the path, i.e.
+
* '''never(!)''' use a variable in the path, i.e. something like
 
:$somepath . 'lib-common.php'
 
:$somepath . 'lib-common.php'
  
 
An older version of the Geeklog/Gallery integration had [http://www.geeklog.net/article.php/2003120922482655 exactly that problem].
 
An older version of the Geeklog/Gallery integration had [http://www.geeklog.net/article.php/2003120922482655 exactly that problem].
  
lib-common.php should also always be the ''first'' file you include in your script. Actually, it should be the first line of code in your script.
+
lib-common.php should also always be the ''first file'' you include in your script. Actually, it should be the ''first line of code'' in your script.

Revision as of 10:22, 10 March 2006

lib-common.php is Geeklog's repository of commonly used functions (those that start with COM_). It also pulls in other libraries, e.g. for the session handling, and ensures that all currently active plugins are loaded.

It is also an important part of Geeklog's security.

Among the files that lib-common.php loads is Geeklog's central configuration file, config.php. By loading this file, it's ensured that all the global $_CONF variables are set and can not be overridden by URL parameters (assuming register_globals is "on").

It is therefore important to properly include lib-common.php, which means

  • always use either the complete, absolute path to your lib-common.php, i.e.
/path/to/your/lib-common.php
  • or use a relative path, i.e.
../../lib-common.php
  • never(!) use a variable in the path, i.e. something like
$somepath . 'lib-common.php'

An older version of the Geeklog/Gallery integration had exactly that problem.

lib-common.php should also always be the first file you include in your script. Actually, it should be the first line of code in your script.