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

From GeeklogWiki
Jump to: navigation, search
m
m (Looks nicer with <pre> ...)
Line 8: Line 8:
  
 
* always '''use either the complete, absolute path''' to your lib-common.php, i.e.
 
* always '''use either the complete, absolute path''' to your lib-common.php, i.e.
:/path/to/your/lib-common.php
+
<pre>require_once('/path/to/your/lib-common.php');</pre>
 
* '''or use a relative path''', i.e.
 
* '''or use a relative path''', i.e.
:../../lib-common.php
+
<pre>require_once('../../lib-common.php');</pre>
 
* '''never(!)''' use a variable in the path, i.e. something like
 
* '''never(!)''' use a variable in the path, i.e. something like
:$somepath . 'lib-common.php'
+
<pre>require_once($somepath . 'lib-common.php');</pre>
  
 
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 20:03, 11 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.
require_once('/path/to/your/lib-common.php');
  • or use a relative path, i.e.
require_once('../../lib-common.php');
  • never(!) use a variable in the path, i.e. something like
require_once($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.