SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Evangelist
    Join Date
    Dec 2008
    Location
    Plymouth, United Kingdon
    Posts
    449
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    include() through HTTP?

    Hi,
    Can I include file through HTTP? I tried the example below from http://uk2.php.net/function.include
    but it is def not working on my localhost.

    Code:
    <?php
    // Won't work; file.txt wasn't handled by www.example.com as PHP
    include 'http://www.example.com/file.txt?foo=1&bar=2';
    
    // Won't work; looks for a file named 'file.php?foo=1&bar=2' on the
    // local filesystem.
    include 'file.php?foo=1&bar=2';
    
    // Works.
    include 'http://www.example.com/file.php?foo=1&bar=2';
    
    $foo = 1;
    $bar = 2;
    include 'file.txt';  // Works.
    include 'file.php';  // Works.
    
    ?>

    This is what I tried to include

    Code:
    <?php include 'http://localhost/mysite/incl_layouts.blog/navigation.php';?>
    Instead of

    Code:
    <?php include("incl_layouts.blog/navigation.php");?>
    Many thanks,
    Lau

  2. #2
    SitePoint Addict
    Join Date
    Apr 2009
    Posts
    248
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    HTTP is a protocol. It literally defines a way of encoding packets to send over the internet.

    If you want to include a remote file, cut the HTTP from the front.

  3. #3
    SitePoint Wizard
    Join Date
    Mar 2008
    Posts
    1,149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why do you need to include a file by URL?

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's pretty rare where you would need to, or should use include on a url. Most of the time, readfile() is what you should use if the file is not on the local filesystem.

    But anyway, you say it "doesnt work". How have you determined it doesn't work? What did you expect to happen? What actually happened?

  5. #5
    SitePoint Evangelist
    Join Date
    Dec 2008
    Location
    Plymouth, United Kingdon
    Posts
    449
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sk89q View Post
    Why do you need to include a file by URL?
    so that i dont have to write this in one file

    PHP Code:
    <?php include("incl_layouts.blog/navigation.php");?>
    and then include the path like this in another file

    PHP Code:
    <?php include("navigation.php");?>
    my idea is to track down the absolute path, so that i dont have to change it so many times when it is located in different locations...

    make sense...?

  6. #6
    SitePoint Evangelist
    Join Date
    Dec 2008
    Location
    Plymouth, United Kingdon
    Posts
    449
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by crmalibu View Post
    It's pretty rare where you would need to, or should use include on a url. Most of the time, readfile() is what you should use if the file is not on the local filesystem.

    But anyway, you say it "doesnt work". How have you determined it doesn't work? What did you expect to happen? What actually happened?
    It wont work bcos the include content doens show on the screen...

    but i think i have found a solution...

    PHP Code:
    <?php echo $path $_SERVER['DOCUMENT_ROOT'].'/mysite/incl_layouts.blog/navigation.php';?>
    <?php 
    include("$path");?>
    result is this,

    HTML Code:
    C:/htdocs/mysite/incl_layouts.blog/navigation.php


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
  •