• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 310
  • Last Modified:

using custom environment variables in php

Hi experts,
I have a scenario as follows:

I have to include one file present in a specific folder to a lot of other files present in different folders.

Is it possible to create a custom environment variable referring to the path of the file to be included, so that instead of hard coding the value of the file path, I can refer to the environment variable in the all the files.

Thanks
0
sandhya01
Asked:
sandhya01
  • 2
  • 2
1 Solution
 
shobinsunCommented:
Hi,

Use this idea:

$thefileroot = $_SERVER["SITE_HTMLROOT"]

And use all files from that html web root.





0
 
Roger BaklundCommented:
You could use the web server variable named DOCUMENT_ROOT, it points to the web server root folder. Use it like this:

include($_SERVER['DOCUMENT_ROOT'].'/path/to/include/myincludefile.php');

Alternatively, use set_include_path('/path/to/include/'), then you can do just

include('myincludefile.php');

http://php.net/set_include_path
0
 
sandhya01Author Commented:
Hi Experts,
Great!! it is working.
But is there any centralized way to do this. I mean, if someday there is a change in the location of the include.php file, i need to manually edit all the files which references include.php, right?
If there is a centralized way to set the value of this file path, like in one file i set a variable to the path of include.php and refer that variable from all the other files. So in case of any change in future, I have to update only one file.

Please advice.

Thanks
0
 
Roger BaklundCommented:
You can modify the include path in the php.ini file.

http://php.net/manual/en/ini.core.php#ini.include-path
0
 
sandhya01Author Commented:
Hi Cxr,
Nice answer, I hope it will work. I will test it tomorrow and will mention the exact way to do this.

Thanks lot
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now