How can I make a link that always refers to the site root. I have an image in an include, and the include appears in many different directories. What's the best way to refer to that image? Any help is greatly appreciated!
g1smd
6:28 pm on Oct 3, 2011 (gmt 0)
Use
a href="/the/path/to/the/file.ext"
with the image reference starting with a slash.
rwilson
7:25 pm on Oct 3, 2011 (gmt 0)
Thank you!
rocknbil
4:07 pm on Oct 4, 2011 (gmt 0)
Just to clarify - for PHP includes and file references, you want the full system path
(exactly the same as the hard coded example above)
But for HTTP requests, such as images, css, etc., you want the root of the domain. So if in the previous example the site is example.com, that would start at public_html (usually:)
/mydata/file.ext
rwilson
5:02 pm on Oct 4, 2011 (gmt 0)
very cool, that may come in handy soon!
Readie
7:37 pm on Oct 4, 2011 (gmt 0)
Just a quick note:
$_SERVER['DOCUMENT_ROOT'], depending on server setup, may or may not have have a trailing slash, so make sure there isn't one by doing: