Link to home
Start Free TrialLog in
Avatar of sandhya01
sandhya01

asked on

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
Avatar of shobinsun
shobinsun
Flag of India image

Hi,

Use this idea:

$thefileroot = $_SERVER["SITE_HTMLROOT"]

And use all files from that html web root.





ASKER CERTIFIED SOLUTION
Avatar of Roger Baklund
Roger Baklund
Flag of Norway image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sandhya01
sandhya01

ASKER

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
You can modify the include path in the php.ini file.

http://php.net/manual/en/ini.core.php#ini.include-path
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