Defining a Home Path in PHP
Tags: PHP, Web Development
- Had trouble with relative links
- Couldn't use
__DIR__
or__FILE__
because it returns a file path instead of a URL
$protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://';
if($_SERVER['HTTP_HOST'] === "stumbling.dev") {
define('HOME_PATH', $protocol . $_SERVER['HTTP_HOST'] . '/');
} else {
define('HOME_PATH', $protocol . $_SERVER['HTTP_HOST'] . '/local-project-folder/');
}