Solved

Set up a config file throughout the site

Posted on 2009-04-03
3
259 Views
Last Modified: 2012-05-06
I have a config file that I want to include throughout the site.  But I don't want to use "include('/path/config.php')" on top of every file.  Is there a way I can set it up somewhere in one place so if I have to change the path, I just change it one time?

Thanks.
0
Comment
Question by:valleytech
  • 2
3 Comments
 
LVL 3

Expert Comment

by:garlix
ID: 24063188
There is the PHP-include-path. See this webpage for more instructions about it.

http://se.php.net/manual/en/ini.core.php#ini.include-path

You can add your own include directory to the includepath using the .htaccess file for your project!
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 24068240
You can set it relative to the document root.  I do this and it is VERY useful when you're moving things around between directories.  See the code snippet for some useful examples.  HTH, ~Ray
// CONFIG PAGE IS ALWAYS IN THE DOCUMENT ROOT

$config_page = $_SERVER["DOCUMENT_ROOT"] . '/' . 'config.php'; require_once($config_page);
 

// CONFIG PAGE IS IN THE CURRENT WORKING DIRECTORY

$config_page = getcwd() . '/config.php'; require_once($config_page);
 

// CODE TO PROTECT CONFIG PAGE FROM RUNNING THE SCRIPT STANDALONE

if (count(get_included_files()) < 2) 

{ 

   header("HTTP/1.1 301 Moved Permanently"); 

   header("Location: /"); 

   exit; 

}

Open in new window

0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 24071752
Thanks for the points.  This is a great question. ~Ray
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now