Is it possible to use PHP INcludes to include a file from an EXTERNAL url?

Discussion in 'PHP' started by BlackCoder, Apr 13, 2007.

  1. #1
    My answer is in the topic. It doesn't matter if I have to use a .php or .html page, I just need it to be external.
     
    BlackCoder, Apr 13, 2007 IP
  2. eugen

    eugen Active Member

    Messages:
    154
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #2
    File must be .php, to be handled as PHP.

    Example: ( see example 16.7 )
    http://www.php.net/manual/en/function.include.php
     
    eugen, Apr 13, 2007 IP
  3. commandos

    commandos Notable Member

    Messages:
    3,648
    Likes Received:
    329
    Best Answers:
    0
    Trophy Points:
    280
    #3
    eugen no ...

    you can include .html , and now answering both , this is legit

    <?php include("filename.html"); ?> 
    PHP:
    or

    <?php include("http://www.example.com/filename.html"); ?>
    PHP:
     
    commandos, Apr 14, 2007 IP
  4. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I would just like to clarify something... although you can include a file from another site, when you include a file (any file... local or remote) via HTTP, you are including the PARSED OUTPUT of that file.

    That is to say, imagine a remote file called hello.php, and imagine it's code is:
    <?php
    print 'Hello World!';
    ?>

    Now, imagine including that remote file via HTTP. The result doesn't include:
    <?php
    print 'Hello World!';
    ?>

    it just includes:
    Hello World!

    as your include via HTTP includes the parsed output: that is to say, the remote server will parse the PHP file and print 'Hello World!'. Your include will include that output... not the actual code itself.

    If you wanted to include a PHP file that was just configuration settings, you would end up including nothing, assuming the file itself doesn't print anything.

    Hopefully that makes sense!
     
    TwistMyArm, Apr 14, 2007 IP
  5. PresFox

    PresFox Active Member

    Messages:
    218
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #5
    also, you need certain settings in your php.ini to be correct. Else, including remote files wont work. I believe this is allow_url_fopen
     
    PresFox, Apr 14, 2007 IP
  6. Subikar

    Subikar Active Member

    Messages:
    241
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #6
    Yes include remote files wont work if you want to display the remote site data then you can open that page in iframe that is the only solution I think so.
     
    Subikar, Apr 15, 2007 IP
  7. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #7
    That's not exactly correct... you can include remote files, but it will only include the output of the file (as I said). The net effect of including via HTTP is generally the same as using an iframe...
     
    TwistMyArm, Apr 15, 2007 IP
  8. 123GoToAndPlay

    123GoToAndPlay Peon

    Messages:
    669
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #8
    using ob_start or curl would do the trick
     
    123GoToAndPlay, Apr 15, 2007 IP
  9. streety

    streety Peon

    Messages:
    321
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #9
    ob_start is to handle output buffering. I don't understand how it would work in this situation.

    curl would definitely work but I suspect it would be like driving in a thumb tack with a sledge hammer. :) Supposed to be more stable though.
     
    streety, Apr 15, 2007 IP
  10. bluesaga

    bluesaga Peon

    Messages:
    102
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #10
    dont see how cURL is so bad, make a function url_open and use it globally, not difficult. And if you have cURL installed its only a few lines of code....
     
    bluesaga, Apr 16, 2007 IP
  11. lionheart008

    lionheart008 Guest

    Messages:
    43
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    It is a huge security risk to include remote files. The php.ini setting allow_url_fopen must be turned on for it to work.

    I can't say I've ever tried this but I believe if you include a straight text file like a ".inc" you can get it to execute locally instead of remotely.
     
    lionheart008, Apr 16, 2007 IP
  12. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #12
    That's true, that should work. Major security risk as far as 'information leakage' can go, but it would work :)
     
    TwistMyArm, Apr 17, 2007 IP
  13. Aragorn

    Aragorn Peon

    Messages:
    1,491
    Likes Received:
    72
    Best Answers:
    1
    Trophy Points:
    0
    #13
    As TwistMyArm said it is possible to include remote files but you will be including the processed output only. if you use the following code
    <?php include 'http://www.google.com/';?> 
    
    Code (markup):
    you can see the google homepage as the output of the page.

    Unless you have complete access to the remote file and what content it will be providing, it is highly adviced not to it because if you do not have control over the content of the remote file then it can be used to gain access to your server.
     
    Aragorn, Apr 17, 2007 IP
  14. BlackCoder

    BlackCoder Peon

    Messages:
    529
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #14
    Thanks everyone for the advice. I will implement it today. Oh, and I do control the content of the remote content. :) Thanks again.
     
    BlackCoder, Apr 18, 2007 IP