Jump to content


Some questions~

  • Please log in to reply
3 replies to this topic

#1 phlai

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 25 July 2006 - 01:28 PM

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?


Index.php      - Default page
Settings.php  - Common variables that can be reused by all the php files
                  - Eg. $Database_name, $Database_username, $Database_password
Category.php -Have a function to retrieve database information.

Index.php include both Settings.php, and category.php by:

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?

#2 trq

  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 25 July 2006 - 01:59 PM

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.


Using require_once() will stop any errors that may occur from trying to include the same file multiple times.

#3 hackerkts

  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 25 July 2006 - 03:26 PM

Just another information, you have to put the require_once before you try to use them.


To be a coder, you must learn how to think and not to give up so easily.

#4 phlai

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 25 July 2006 - 04:00 PM

Oh ic!! Thanks!! I will try it out!!  ;D

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users