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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
http://php.net/manual/en/ini.core.php#ini.include-path
ASKER
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
Nice answer, I hope it will work. I will test it tomorrow and will mention the exact way to do this.
Thanks lot
Use this idea:
$thefileroot = $_SERVER["SITE_HTMLROOT"]
And use all files from that html web root.