Solved

Set up a config file throughout the site

Posted on 2009-04-03
3
247 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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks for the points.  This is a great question. ~Ray
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

763 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

8 Experts available now in Live!

Get 1:1 Help Now