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 Include question

Discussion in 'PHP' started by Boris4ka, Apr 21, 2008.

  1. #1
    Ok let me try to explain..

    head.php
    directory/page.php

    I need to phpinclude head.php INTO page.php. So page.php would have the include command.

    Why doesn't <?php include("/head.php"); ?> work? ../ doesn't, and ./ doesn't also. Is it something with my host's PHP config? Or am I doing something wrong?

    Oh and http includes aren't allowed.

    Please help, thanks:)
     
    Boris4ka, Apr 21, 2008 IP
  2. Rob Whisonant

    Rob Whisonant Well-Known Member

    Messages:
    156
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    110
    #2
    Try using the full path.

    /home/httpd/fullpath/to/the/file/on/the/server

    Re's
    Rob Whisonant
     
    Rob Whisonant, Apr 21, 2008 IP
    Boris4ka likes this.
  3. CPURules

    CPURules Peon

    Messages:
    67
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    
    <?php
    include($_SERVER['DOCUMENT_ROOT'] . "/../head.php");
    ?>
    
    PHP:
    Try that out :)
     
    CPURules, Apr 21, 2008 IP
  4. osdude

    osdude Peon

    Messages:
    76
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    you don't need parenthesis

    I believe, the path is relative to the script that is running. I always use full working path, because error pages call the "/" site root wrong when using include other than a full path.

    KWIM?


    <?php @include 'public_html/yoursite/head.php'; ?>
     
    osdude, Apr 21, 2008 IP
  5. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #5
    Simple...
    <?php include '../head.php'; ?>
    Code (markup):
    If you want to use absolute paths (recommended), have a constant or variable named app_root or similar and prefix filenames with it.
     
    krt, Apr 21, 2008 IP
  6. Boris4ka

    Boris4ka Well-Known Member

    Messages:
    172
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    110
    #6
    Ok I tried all of them and this is the only one that worked. Thanks:D
     
    Boris4ka, Apr 21, 2008 IP
  7. Rob Whisonant

    Rob Whisonant Well-Known Member

    Messages:
    156
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    110
    #7
    You are welcome. Glad I could help.

    Re's
    Rob Whisonant
     
    Rob Whisonant, Apr 22, 2008 IP