I am building a website utilizing minimal PHP. My first application was using includes. I have inserted the following inside various elements such as <nav></nav> to streamline website wide changes.
As you can see, I also used the Global variable (Not sure if that is precisely correct terminology) when "including" my 'nav.php' file. At first I was just using relative links. But then I decided it would be a lot easier if I could just do everything in relation to root. Then I discovered the HTML, CSS, and PHP think of different directories as root.Code:<?php include($_SERVER['DOCUMENT_ROOT']."/static/nav.php"); ?>
I believe that PHP considers '/' the actual root directory on the server, while HTML and CSS use the domains root directory (or the directory that the file being executed is in?)
Anyway, utilizing the $_SERVER['DOCUMENT_ROOT']. text works, although I wasn't sure why it wasn't like this:
Note that I dropped the '.' and put the $_SERVER['DOCUMENT_ROOT'] inside the quotes with the /static/nav.php.<?php include("$_SERVER['DOCUMENT_ROOT']/static/nav.php"); ?>
This seems much more intuitive to me, consider that I figured it would just substitute the text '/var/www' directly for the $_SERVER['DOCUMENT_ROOT'].
What is the '.' for and why does it have to be outside the quotes??
Also, I wasn't able to get this method to work when the include was inside carrots. For instance. I have an include link to 'links.php'
The 'links.php' file looks like such:
I could not make the previous server-'document_root' method work inside the <link /> element. But after creating an .htaccess file and adding the line:Code:<link rel="stylesheet" type="text/css" href="<?php include(root_path); ?>/css/reset.css" /> <link rel="stylesheet" type="text/css" href="<?php include(root_path); ?>/css/master-style.css" /> <link rel="icon" type="image/png" href="<?php include(root_path); ?>/images/blue.png" />
I was able to make it work.Code:php_value root_path "/var/www"
I don't understand why I couldn't use the first method. This was the only way I could get this to work. Additionally, I couldn't use this method in the first scenario because it would involve putting an include inside an include.
Do I need to use both of these methods depending on the circumstances, or should I be able to utilize just one?
Any knowledge you would care to share on these topics, what is actually happening, what you recommend etc would be greatly appreciated!