PHP Include doesn't work on every page?

Discussion in 'PHP' started by urmick96, Mar 26, 2011.

  1. #1
    urmick96, Mar 26, 2011 IP
  2. urmick96

    urmick96 Active Member

    Messages:
    236
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #2
    Nevermind I have now fixed this issue.
     
    urmick96, Mar 26, 2011 IP
  3. Darkfired

    Darkfired Peon

    Messages:
    25
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    What was wrong? And what was the solution?
     
    Darkfired, Mar 26, 2011 IP
  4. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #4
    I assume that the include path was incorrect since they are in different directories but using the same exact code.

    If in tools/index.php
    
    include('filename.php');
    
    PHP:
    In index.php you would change it to:

    
    include('tools/filename.php');
    
    PHP:
    However, I always advise people to use the absolute path instead of relative ones:

    
    $fileName = basename($_SERVER['SCRIPT_FILENAME']);
    define('BASEPATH',str_replace($fileName,'',$_SERVER['SCRIPT_FILENAME']));
    
    include(BASEPATH . 'filename.php');
    
    PHP:
     
    ThePHPMaster, Mar 26, 2011 IP
  5. urmick96

    urmick96 Active Member

    Messages:
    236
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #5
    Yeah well I was using like

    
    include("http://www.drixxel.com/include/footer.txt");
    
    PHP:
    But my webhost didnt allow the http part so this worked

    
    include("../include/footer.txt");
    
    PHP:
     
    urmick96, Mar 27, 2011 IP