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

From GeeklogWiki
Jump to: navigation, search
m (Looks nicer with <pre> ...)
m (leave braces off of the require_once)
 
(One intermediate revision by the same user not shown)
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.
<pre>require_once('/path/to/your/lib-common.php');</pre>
+
<pre>require_once '/path/to/your/lib-common.php';</pre>
 
* '''or use a relative path''', i.e.
 
* '''or use a relative path''', i.e.
<pre>require_once('../../lib-common.php');</pre>
+
<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
<pre>require_once($somepath . 'lib-common.php');</pre>
+
<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.
 +
 +
 +
[[Category:Development]]

Latest revision as of 17:40, 21 May 2009

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.