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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With