Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

when placeing a config file outside the public root. how do i call it on every page without defining the path

this is how my file structure is. [..] are folders

[public]
[libs]
[crontab]
[logs]
[sessions]
[tmp]

config.php

the domain is set to the public folder as its root. everything else including the config.php file is outside the root. the config contains db connection information and other necessary settings.

every page in the public folder i have to put the entire path so include the config file. problem is when i move everything from my local machine to the public server i have to go through every page and change the path included for the config file. is there a better way? maybe settings a path in php.ini or something like that?

thanks

like image 415
Exploit Avatar asked Oct 22 '11 22:10

Exploit


1 Answers

In that specific case you can use:

include("$_SERVER[DOCUMENT_ROOT]/../config.php");
# Note: special exception array syntax within double quotes.

Which resolves to the public directory first, but moves one level back ../ to reach the config file outside of the docroot.


But you could also use SetEnv in your .htaccess to define another $_SERVER environment variable for the occasion.

like image 180
mario Avatar answered Sep 18 '22 17:09

mario