A better way to include a config file? (PHP)



  •  Here's my problem. I have a config file, and everything, including paths are stored in it. I've got the kitchen sink in it too. It makes my PHP app more modular and easier to configure.

    There's just one problem. I have to include the config file to get the configurations, and to do that I have to use a relative or absolute path at the top of every page. If my customer wishes to change the structure of the files, say split them between servers, rename the folders, put everything in one folder, they would have to open every php file and change the include path for every single one of them because the config file would be somewhere else.

    Currently if they want to change the structure, they only need to change the values in the config file, and the path to the config file (every page).

    Is there a way around this or am I stuck with this?



  • Check out the auto_prepend directive in php.ini.  It should take care of what you need. 



  •  I won't have access to the php.ini :( Which is stupid but that's the way it is. I'm only one department ina big group of departments and we don't get our own server.



  • @malfist said:

    I won't have access to the php.ini :( Which is stupid but that's the way it is. I'm only one department ina big group of departments and we don't get our own server.

    You should be able to set the configuration in the vhost or possibly even .htaccess.  It would prevent you from having to include the config in every file, too. 



  •  IIS, no .htaccess. I wouldn't know how to do it with the vhost. My department shares the server with the rest of IT and all their websites. We all have subdomains but I don't know about vhost, I'm vaguly familar with the term but don't know what it means, forgive my ignorance, can you enlightenment.



  • @malfist said:

    We all have subdomains but I don't know about vhost, I'm vaguly familar with the term but don't know what it means, forgive my ignorance, can you enlightenment.

    Basically a vhost (virtual host) corresponds to a site on the server.  So all of the subdomains on the same server are their own vhosts.  I don't know much about configuring IIS but I did find this: http://www.iis-aid.com/articles/how_to_guides/setting_per_directory_php_configuration_values

     

    That will allow you to modify individual php.ini configuration values on a per-directory basis and should work with auto_prepend_file.  The auto_prepend_file configuration variable lets you set a file that is included before every single request.  This is useful for setting up global settings that would otherwise require boilerplate code at the top of each file.  I know a lot about PHP but IIS is not my area of expertise so that's about all I can offer.  I suggest Googling for ways to get per-directory or per-vhost settings for PHP on IIS.


Log in to reply