Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Set up a config file throughout the site

Posted on 2009-04-03
3
Medium Priority
?
297 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 111

Accepted Solution

by:
Ray Paseur earned 2000 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 111

Expert Comment

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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month20 days, 21 hours left to enroll

810 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