PHP Include problem

Discussion in 'PHP' started by nsusa, Nov 30, 2006.

  1. #1
    I am having problems with PHP include. I do have a script that generates pages on the fly when requested by a user or a search engine. I need to include some extra stuff and are using the PHP include function to pull the code in.

    The problem is that the include (see bold code) apparently does not get executed. Now for testing I pasted my code from the file I was trying to include directly into the page and it executes just fine.

    What could be the cause for this? The file permissions on the include file are normal. Other includes are working fine.

    Thanks.

    Christoph
     
    nsusa, Nov 30, 2006 IP
  2. Jim bob 9 pants

    Jim bob 9 pants Peon

    Messages:
    890
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #2
    <?php include('http://www.mydomain.com/subfolder/additionalfile.php'); ?>

    try

    <?php include("http://www.mydomain.com/subfolder/additionalfile.php"); ?>

    I use this <?php include("../includes/leftnav.php"); ?>
     
    Jim bob 9 pants, Nov 30, 2006 IP
  3. BrianR2

    BrianR2 Guest

    Messages:
    734
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I've had problems with include() using absolute paths. Try using relative paths like <?php include('../subfolder/additionalfile.php'); ?> with the correct path to the file and it should work.
     
    BrianR2, Nov 30, 2006 IP
  4. nsusa

    nsusa Peon

    Messages:
    858
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    0
    #4
    It was the absolute path thingy. ;) Now it works. Awesome guys. Thank you so much.

    Christoph
     
    nsusa, Nov 30, 2006 IP
  5. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Just a heads up: including via HTTP doesn't do what you would expect it to do as the server parses the PHP first.

    BrianR2: I find it interesting that you've had problems using absolute paths... the only problems I've had was with relative ones (for example, including a file in one directory which includes another file where a file with that name exists in multiple directories).

    I use a 'combination' of relative paths and dirname( __FILE__ ): that way I essentially get to use relative paths as I would expect them to work.
     
    TwistMyArm, Nov 30, 2006 IP
  6. BrianR2

    BrianR2 Guest

    Messages:
    734
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    0
    #6
    maybe it depends on the server settings. i thought i had used absolute paths before without problems.
     
    BrianR2, Nov 30, 2006 IP
  7. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I agree that absolute paths aren't perfect: moving to different servers and so on requires changes to files. That's why I use that combination as it basically gives me 'dynamic absolute' directories.
     
    TwistMyArm, Nov 30, 2006 IP