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.

php includes from different directory

Discussion in 'PHP' started by Lpspider, Sep 24, 2005.

  1. #1
    I'm working on my site...now, I can link content from a sub directory to a "above" directory, but how can I link to a page in a subdirectory that calls to content from the above directory?

    Hope that wasn't too confusing.

    Thanks for any help.
     
    Lpspider, Sep 24, 2005 IP
  2. nevetS

    nevetS Evolving Dragon

    Messages:
    2,544
    Likes Received:
    211
    Best Answers:
    0
    Trophy Points:
    135
    #2
    It's always best to link to the file by using the full path.

    The best scenario is to create an "includes" directory, then set the include path to a variable and reference that in all your files. If you use the ini path variable, it will search the include directories for the file all the time.

    example:

    
    $include_path = "/usr/local/apache/htdocs/includes/"
    require_once($include_path . "header.php");
    
    PHP:
    If you really need a relative path, you can always do something like:
    
    require_once("../header.php");
    
    PHP:
     
    nevetS, Sep 24, 2005 IP
  3. puLse

    puLse Peon

    Messages:
    134
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yeah, you can use ../ as many times as you want to go back a directory. For example, if your script is located in the directory main/php/blah/ and you want to include a file called "dog.php" located in the directory /main/, you would do this:

    
    include "../../dog.php";
    
    PHP:
    Hope I helped :)
     
    puLse, Sep 25, 2005 IP
  4. michele

    michele Peon

    Messages:
    30
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    But dont ever accept "../" in any user input. If you do, people could view all sorts of files on your computer!
     
    michele, Sep 26, 2005 IP