Try a path to the included file
- include '/your/path/to/folder/includes/config.php';
it'll be better if you have one file that includes all other files - your admin.php just includes other needed files - the tab.php file. And then in your admin file you make all the configuration needed to run your site.
Or if you have you config file in an array, or if it is an object you can use the global var scope.
Here are 2 examples:
- array styled config file
- object styled config file
PHP Code:
<?php
// The config file
// Array style
$config = array( 'database' => array( 'username' => 'mysql_user',
'pass' => 'mysql_pass',
'database' => 'db'
),
'site_name' => 'The site',
'caching' => '0'
);
// Object style
class siteConfig {
protected $database = array( 'username' => 'mysql_user',
'pass' => 'mysql_pass',
'database' => 'db'
);
protected $site_name = 'The site';
protected $caching = '0';
}
?>
Now you structure your admin.php
PHP Code:
<?php
include '../includes/config.php';
/*
* If you are using the array styled config file
* your configuration is avaible trought the $config var
* or any other you defined ($conf, $c ...)
*/
// If using the object style config file
$config = new siteConfig();
// Using the object styled
// Example:
mysql_connect( 'localhost', $config->database['username'], $config->database['pass']);
// And here you include your files that depend on, let's say,
// page var
$page = $_GET['page'];
switch( $page ) {
case 'news':
include 'somefile.php';
break;
default:
include 'mainFile.php';
break;
}
?>
Now when you include the file - no need for config.php to be included again and again - this way you built a platform for your included fileds.
And if you are using functions and you need to access the $config - you use the
global variable scope
PHP Code:
<?php
function test() {
global $config;
// The stuff the function does
}
?>