- This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
Viewing 3 posts - 1 through 3 (of 3 total)
- The forum ‘Back End’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
So normally all my includes look like this or some variation…
If I use a absolute path like this… it will not work and throw an error.
I now there is a way by specify the root or something within the include or above it so I CAN USE an absolute path within my include? Can someone please show me? Thanks!
Thanks for pointing me in the correct direction. Looks like you can even do it easier with this bit…
Yep! That’s how I roll with includes, works a treat! You can still do usual paths beginning with / for CSS/JS but PHP/Apache use the full document root, rather than relevant to the URL.
So for example if you had your stylesheet linked as ‘/css/styles.css’ – this would work fine as it’s going “http://domain.com/css/styles.css”.
However, because PHP can see the whole route, your path is actually the file/folder path of the server. So “/css/styles.php” would go all the way back to the OS structure, for example if your site was at “/var/www/sitex/live_site/index.php” it would go back to before /var looking for that file.
So $_SERVER tells PHP to look in /var/www/sitex/live_site/ and thusly finds your file!
It took me forever to work that out when I first started messing around with PHP includes!