1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to make relative link structure?

Discussion in 'HTML & Website Design' started by Nima, Jul 19, 2007.

  1. #1
    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..
     
    Nima, Jul 19, 2007 IP
  2. eadkung

    eadkung Active Member

    Messages:
    148
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    58
    #2
    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 :)
     
    eadkung, Jul 19, 2007 IP
  3. Nima

    Nima Well-Known Member

    Messages:
    3,489
    Likes Received:
    243
    Best Answers:
    0
    Trophy Points:
    175
    #3
    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.
     
    Nima, Jul 19, 2007 IP
  4. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #4
    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
     
    AstarothSolutions, Jul 20, 2007 IP
    Nima likes this.
  5. Nima

    Nima Well-Known Member

    Messages:
    3,489
    Likes Received:
    243
    Best Answers:
    0
    Trophy Points:
    175
    #5
    how about for .php?
     
    Nima, Jul 20, 2007 IP
  6. AdamSee

    AdamSee Well-Known Member

    Messages:
    422
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    135
    #6
    AdamSee, Jul 20, 2007 IP
    Nima likes this.
  7. Nima

    Nima Well-Known Member

    Messages:
    3,489
    Likes Received:
    243
    Best Answers:
    0
    Trophy Points:
    175
    #7
    Do i have to replace the "document_root" with anything?
     
    Nima, Jul 20, 2007 IP
  8. AdamSee

    AdamSee Well-Known Member

    Messages:
    422
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    135
    #8
    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>
     
    AdamSee, Jul 20, 2007 IP
  9. tayiper

    tayiper Active Member

    Messages:
    421
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    78
    #9
    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
     
    tayiper, Jul 21, 2007 IP
  10. eadkung

    eadkung Active Member

    Messages:
    148
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    58
    #10
    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 ;)
     

    Attached Files:

    eadkung, Jul 21, 2007 IP