SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru kgtrip's Avatar
    Join Date
    Jun 2003
    Location
    Karplakistan
    Posts
    804
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    include doesn't work properly

    Hi mates,

    I don't know what am I doing wrong, but my include doesn't work well.
    I have 2 files:
    a.php

    <?php
    $a=5;
    ?>

    b.php
    <?
    include 'a.php';
    echo $a;
    ?>

    Everything works fine when these 2 files are on the same directory. However when put on different directories the trouble begins. as shown here:

    Lets sat file a.php is on my main directory, and I put file b.php in a sub folder /tmp

    Now I change the path to file a.php, which is in a folder above and I do something like:

    b.php
    <?
    include 'http://www.domainname.com/a.php';
    echo $a;
    ?>

    This results iin noting, nadda, ziltch. Now I need to use this absolute path cause file b.php would change positions from time to time. Can it be done?
    Compare Hundreds of Web Hosting Plans

  2. #2
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,000
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You cannot include file over URL because it returns only html code, not php code. You must do that directly over file system.
    Therefore, you need to look at your php info and find document root then include your file using absolute path to it or even using relative one.
    For example in your case this should work fine:
    Code:
    <?php include "../a.php"?>
    -- Jelena --

  3. #3
    SitePoint Guru kgtrip's Avatar
    Join Date
    Jun 2003
    Location
    Karplakistan
    Posts
    804
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jelena
    You cannot include file over URL because it returns only html code, not php code. You must do that directly over file system.
    Therefore, you need to look at your php info and find document root then include your file using absolute path to it or even using relative one.
    For example in your case this should work fine:
    Code:
    <?php include "../a.php"?>
    Thanks jelena,

    worked just fine
    Compare Hundreds of Web Hosting Plans


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •