I'm using php includes to call the navigation bar. Im about to start adding some content and will need to go into subfolders. At that point, the links are going to need ../ in front of them to work correctly. How can I do this without having to make multiple navbar php files? Possible? It would be really nice to only have to edit 1 file to change my site navigation.
Either use absolute links /gallery/pictures/1.jpg instead of ../gallery/pictures/1.jpg or use the head tag <base href="http://www.yourdomain.com"> and make all the links relative to that address
or make the links proper like instead of link being /page.php make the link http:// site.com/page.php
There is no speed or efficiency difference between fully qualified and relative urls. You have a few different options - Hard code fully qualified directories/links. For url links you could just do <a href="/path/to/your/file.jpg">... or if you are using php variables and need them to work during processing, use the full path name to the file $filename = "/path/to/your/file.jpg" or maybe $imagedir = "/path/to/your/"; $filename = $imagedir."file.jpg" You could also parse out $PHP_SELF to get the location of your current script, and adjust your filenames using str_replace.
I dont understand whats causing me to get this error: Warning: main(): open_basedir restriction in effect. File(/includes/topmeta.php) is not within the allowed path(s): (/home2/modded:/usr/lib/php:/usr/local/lib/php:/tmp) in /home2/modded/public_html/articles/index.php on line 1 line 1 in the php file is <?php include("/includes/topmeta.php"); ?> the topmeta.php address is mysite.com/includes/topmeta.php
the path in your php include is a filesystem path - not a web url path. You need to either use a relative path, or the absolute file system path - something like: <? include("/home2/modded/public_html/includes/topmeta.php"); ?> PHP:
You do realize you can include files in higher directories with ../ right? You have a file file.php in /home/subdir/file.php topmeta.php is in /home/includes/topmeta.php You want to link to /home/subdir/subdir2/file2.php So in file.php just do a <?php include "../includes/topmeta.php"; ?> The links will be relative to wherever file.php is not topmeta.php so it'll work fine.
yes I do, but I didn't realize it was pulling from the file root. I assumed, because I used absolute links in the images as well, that files were pulled the same way. I'll give it a shot. ***edit*** I used nevetS method, works great. thanks.