Support » Fixing WordPress » Include PHP files at absolute URLs?

  • gmaletic

    (@gmaletic)


    I’m creating a custom theme for my web site, but I want to ‘php include’ some files that are located outside of my WordPress installation, via an absolute URL.

    When I try this, I get an error:

    <b>Warning</b>:  include() [<a href='function.include'>function.include</a>]: URL file-access is disabled in the server configuration in <b>/home/.pea/gmaletic/tilt-movie.com/blog/wp-content/themes/Tilt/header.php</b> on line <b>28</b><br />
    <br />
    <b>Warning</b>:  include(http://staging.tilt-movie.com/navbar.php) [<a href='function.include'>function.include</a>]: failed to open stream: no suitable wrapper could be found in <b>/home/.pea/gmaletic/tilt-movie.com/blog/wp-content/themes/Tilt/header.php</b> on line <b>28</b><br />
    <br />
    <b>Warning</b>:  include() [<a href='function.include'>function.include</a>]: Failed opening 'http://staging.tilt-movie.com/navbar.php' for inclusion (include_path='.:/usr/local/php5/lib/php:/usr/local/lib/php') in <b>/home/.pea/gmaletic/tilt-movie.com/blog/wp-content/themes/Tilt/header.php</b> on line <b>28</b><br />

    It seems as if there is some setting I could change that would allow me to include files at arbitrary locations…am I right? How do I do this?

    Thanks very much.

Viewing 4 replies - 1 through 4 (of 4 total)
  • haochi

    (@haochi)

    You can’t include PHP files this way because they are output as HTML rather than PHP code so they won’t be treated as PHP codes.

    You probably want to use $_SERVER['DOCUMENT_ROOT'].
    http://php.net/reserved.variables

    Thread Starter gmaletic

    (@gmaletic)

    Let me explain it this way. When I use a line in my page like:

    <?php include("banner.php"); ?>

    …it works fine. But if I change this line to be:

    <?php include("http://www.Tilt-Movie.com/banner.php"); ?>

    …it breaks. Is there a way for me to configure my server so this does work?

    Thanks very much.

    Dion Hulse

    (@dd32)

    Meta Developer

    As the error says, You cant include a file via a URL like in your 2nd code example.

    Your best bet is something like this:

    <?php include(ABSPATH . "banner.php"); ?>
    For something in the folder wordpress is installed in, Or:
    <?php include(ABSPATH . "../banner.php"); ?>
    For something in the folder above where WP is installed in
    (ie. WP = http://&#8230;./wordpress/ banner.php = http://&#8230;./banner.php)

    Cheers,
    Dion

    Thanks, Dion / dd32!

    Using your example I am able to link to a php file on a sibling folder on the root of the domain.

    At least temporarily for testing purposes.
    Need to work out a couple other things now 😉

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Include PHP files at absolute URLs?’ is closed to new replies.