phlai Posted July 25, 2006 Share Posted July 25, 2006 Hi Guys,Im new to php.. May i ask some questions?If I want to centralize some of the common variables into a php file, and access them through it, may i know how?Example..Index.php - Default pageSettings.php - Common variables that can be reused by all the php files - Eg. $Database_name, $Database_username, $Database_passwordCategory.php -Have a function to retrieve database information.Index.php include both Settings.php, and category.php by: require_once("Settings.php"); require_once("Category.php");But when in Category.php i want to use the variable $Database_name i cannot access it.. Is there a offical way to store all the common variable in the common access php file? Quote Link to comment https://forums.phpfreaks.com/topic/15582-some-questions~/ Share on other sites More sharing options...
trq Posted July 25, 2006 Share Posted July 25, 2006 The way you have described your layout, and variables within Settings.php will be available within Category.php if called from within index.php.If you want to call Category.php by itself and still access variables from within Settings.php, you will need to include Settings.php into Category.php.[code=php:0]require_once("Settings.php");[/code]Using require_once() will stop any errors that may occur from trying to include the same file multiple times. Quote Link to comment https://forums.phpfreaks.com/topic/15582-some-questions~/#findComment-63382 Share on other sites More sharing options...
hackerkts Posted July 25, 2006 Share Posted July 25, 2006 Just another information, you have to put the require_once before you try to use them. Quote Link to comment https://forums.phpfreaks.com/topic/15582-some-questions~/#findComment-63433 Share on other sites More sharing options...
phlai Posted July 25, 2006 Author Share Posted July 25, 2006 Oh ic!! Thanks!! I will try it out!! ;D Quote Link to comment https://forums.phpfreaks.com/topic/15582-some-questions~/#findComment-63457 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.