using custom environment variables in php

Posted on 2009-04-30
Last Modified: 2013-12-13
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.

Question by:sandhya01
    LVL 14

    Expert Comment


    Use this idea:

    $thefileroot = $_SERVER["SITE_HTMLROOT"]

    And use all files from that html web root.

    LVL 39

    Accepted Solution

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


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


    Author Comment

    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.

    LVL 39

    Expert Comment

    by:Roger Baklund
    You can modify the include path in the php.ini file.

    Author Comment

    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

    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

    Both Easy and Powerful How easy is PHP? (  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
    Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
    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 …

    728 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

    16 Experts available now in Live!

    Get 1:1 Help Now