Hey, How can I make relative link structures? I know for example ../../index.php would go up two folders and get the index.php file, BUT all my web pages have the same header (header.php) so the relative link has to be something to work for all of them. Is there anyway to do that? I hope I communicated my problem well..
i suppose your directory structure is something like this when you want to include header.php in your pages, a link that you point to header.php will be different depends on how deep of your page in directory structure. >> index.php include("include/header.php"); PHP: >>deep-page.php include("../include/header.php"); PHP: >>deeper-page.php include("../../include/header.php"); PHP: i hope that's what you want
Thanks for the help... That is what I'm doing right now. But I'm wondering if there is anyway to make it a general line that would work for all of them. So that for example it would figure out what the most top directory is and grab header.php from there... But my question was mainly for general links on the website (for example a link that points to the homepage). I don't want to write it as <a href=''www.homepage.com">.... I want it to point to the top folder.
With .Net it is simple as you have the ~ which makes the link relative to the root - particularly useful when you have dynamic URL rewriting so your include would have been include("~/include/header.aspx") for all pages, no matter how deep
In PHP it's $_SERVER['document_root'] Some other good ones here; http://uk.php.net/reserved.variables
You don't need to, this finds the root of the domain. Unless you want to find something else ( say the site the person has some from). So $_SERVER['xxx'] where xxx is equal to any variables on the page linked to above. You might want to try adding this to a php file and see what result it generates. <h1><?=$_SERVER['document_root']?></h1>
Hmmm, maybe you can try to use the "base href=" (which is used to explicitly specify the "root" directory) to see if it helps; see the example of of a few such lines taken from one of my own websites right below this paragraph. The example with five such "base" lines: <base href="http://tadej-ivan.50webs.com/" /> Code (markup): <base href="http://tadej-ivan.50webs.com/legal/" /> Code (markup): <base href="http://tadej-ivan.50webs.com/other/" /> Code (markup): tayiper
if you try to refer to something such as an image, you use $_SERVER['DOCUMENT_ROOT'] to refer to root directory and then follow with your images directory like: <img src="<?=$_SERVER['DOCUMENT_ROOT'].'/test_rellink/images/header.jpg'?>" /> HTML: "$_SERVER['DOCUMENT_ROOT']" is a common relative link that can use in any pages. i may not explain well, so try my code. i just run it before reply your topic, it's work perfectly