Forum Moderators: coopster
href="link.php3"
how can i add the server path so that the links work no matter ,where in the file system the fiels are located.
kumar
php, templates and folder directives [webmasterworld.com]
Accessing PHP includes folder in root dir from 2+ levels deep [webmasterworld.com]
my link.inc is in root, and i added
<? include $_SERVER['DOCUMENT_ROOT'] . "/link.inc";?>
to a file bands.php in a folder called stuff. but when i open bands.php then the links , instead of linking to the file guitar.php which is outside stuff, links to it as if it was inside stuff.
any suggestions?
<? include $_SERVER 'DOCUMENT_ROOT'] . "/link.php3";?>
and this is in m,y link.php3 file
<a class="menulink" href="<? include $_SERVER['DOCUMENT_ROOT'] . "/ph_album.php3"?>"> PHOTO ALBUM </a>
<a class="menulink" href="<? include $_SERVER['DOCUMENT_ROOT'] . "/cd.php3"?>"> CD REVIEWS </a>
<a class="menulink" href="<? include $_SERVER['DOCUMENT_ROOT'] . "/stuff.php3"?>"> STUFF </a>
would this make sense....cause all of a sudden when i load the first page that contains the include i get an error that apache has generatod error and will be closed by windows etc...
any idea if im, doing something wrong here...
im, gonn arestart the system, and try agian in the mean time
Here's the part in the manual about server vars [php.net]
<a class="menulink" href="<?= $_SERVER['DOCUMENT_ROOT'] . "/ph_album.php3"?>"> PHOTO ALBUM </a>
<a class="menulink" href="<?= $_SERVER['DOCUMENT_ROOT'] . "/cd.php3"?>"> CD REVIEWS </a>
<a class="menulink" href="<?= $_SERVER['DOCUMENT_ROOT'] . "/stuff.php3"?>"> STUFF </a>
<?= is shorthand for echo
What jatar_k is saying is that you don't need the include function, you simply want to echo or print the value of the DOCUMENT_ROOT concatenated to the path you are specifying. Therefore, don't use
include and echo the value out:
<a class="menulink" href="<?= $_SERVER['DOCUMENT_ROOT'] . "/stuff.php3"?>">STUFF</a>
<a class="menulink" href="<?php echo $_SERVER['DOCUMENT_ROOT'] . "/stuff.php3"?>">STUFF</a>
<?= is PHP shorthand for echo if short-open-tag [php.net] is ON.
let me explain (i am kinda excited, having found my first answer to why a script is not working, he he). the welcome.php3 page (where the include is working) is called with the address [localhost...] but all the other pages are called using a link from this page.
and the links are created using the $_server['document_root']. so while the welcome page is being called "trough" the server, the other pages are not. why? becaue the
$_server['document_root'] returns
c:/program files/easyphp1-7/www/
and using this to call the file is not going "trough" the server. i kinda dicovered this when i just opened the welcome.php3 by double clicking on it in its folder. then i tried calling the other files by entering the URL in the address bar and there you go, the include statemnts worked.
so my question is....how do i avoid this, if there is a way...? and will it work on the host server...(its almost 4 am and i wanna go to sleep....cant be botheresd trying out just now...:)...).
thanks guys, and i hope my dicovery is of use at some point in time and place for some tested soul...
kumar
partly my fault
when including it does using the filesystem so you need the DOCUMENT_ROOT part.
When outputting a link, you only need the path in relation to the root of the website.
so
<? include $_SERVER['DOCUMENT_ROOT'] . "/link.php3";?>
but in the file that is included you only need to reference from the root of the site for web links
<a class="menulink" href="/ph_album.php3"> PHOTO ALBUM </a>
<a class="menulink" href="/cd.php3"> CD REVIEWS </a>
<a class="menulink" href="/stuff.php3"> STUFF </a>
the conversation about include got me all confused
file.php
you have specified that it is in the same folder as the present file.
when you start your path with a / you are saying start at the root.
If you do this in an href it will start at the root directory of the web site. If you are using filesystem functions like include or require it will start looking at the server root.
Warning: Failed opening '/home/p/pt/pt-home/public_html//link.php3' for inclusion (include_path='.:/usr/local/lib/php') in /mnt/home4/k/ku/kumar/public_html/welcome.php3 on line 56
this is line 56
<? include $_SERVER['DOCUMENT_ROOT'] . "/link.php3";?>
any advice..?