I currently have the following in a config file in my application:
define('DOCROOT', dirname(__FILE__).DIRECTORY_SEPARATOR);
define('WEBROOT', 'http://localhost/samples/');
The first line works perfectly. I can include the config file anywhere and then use the DOCROOT
constant as expected.
The second line works as well, but it's hardcoded, which means that when I upload this file to my webserver, it will be wrong. There it should be http://samples.example.com
. Is there a good way to somehow prevent this hard coding? I kind of think that I have to hard code something somewhere, and in that case, what and how little can I get away with?
I use the following code to find the base URL:
function getBaseURL() {
return 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . '://'
. $_SERVER['HTTP_HOST']
. rtrim(dirname($_SERVER['SCRIPT_NAME']), '/\\')
. '/'
;
}
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