I’m using WAMP and have a development site in the www directory. I want to use dirname(__FILE__) to define the path to the server root.
Currently I’m using a config file which contains:
define('PATH', dirname(__FILE__));
I’m including the config file in in my header.php file like this:
<?php require_once("config.php") ?>
Then, on my sub pages I use the constant PATH to define the path by including header.php.
<?php require_once("../inc/header.php"); ?>
However, my links are coming out like this:
<link rel="stylesheet" href="C:\wamp\www/css/style.css" />
What do I need to do to fix this? And since I’m including my constant in the header.php file I don’t have access to the constant in the initial require_once("../inc/header.php"); What other method can I use to find the root for header.php?
It looks like you just need to have
If you want to be super technical, you can do something like this instead.
On a side note, and more importantly, you don’t actually need them. This will work.
When a href begins with a directory separator, it is considered relative to the document root, not the current working directory.