Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jun 2008
    Posts
    93
    Thanks
    12
    Thanked 1 Time in 1 Post

    Question about PHP Includes

    Hi,

    I was wondering if PHP includes only work if the file is on the same server or whether it can grab and 'include' files from other servers.

    Thanks

  • #2
    Regular Coder Zangeel's Avatar
    Join Date
    Oct 2007
    Location
    public_html/
    Posts
    638
    Thanks
    17
    Thanked 79 Times in 79 Posts
    Only if your server configuration allows URL File Access. But you can't access it's Server Side codes, just it's HTML and client side stuff, like file_get_contents().
    PHP Code:
    $aString is_string((string)array()) ? true false// true :D 
    [/CENTER]

  • Users who have thanked Zangeel for this post:

    millsi80 (09-11-2009)

  • #3
    New Coder
    Join Date
    Jun 2008
    Posts
    93
    Thanks
    12
    Thanked 1 Time in 1 Post
    Ah, alright thanks

  • #4
    Regular Coder
    Join Date
    May 2009
    Location
    Moore, OK
    Posts
    282
    Thanks
    11
    Thanked 41 Times in 41 Posts
    You can however, if you have control over both servers (and highly recommend doing this only if you do), you can use php to write out php onto the html page. Then access it using an include, but you must also make sure you have url_include turned on in php. It is shutoff normally by default because it can lead to an attack on your website if you do not control the site being accessed.

    Ex. Script 1 - File name is 'script_1.php' at http://www.server_a.com
    PHP Code:
    <?php
      
    echo '<?php echo "hello world"; ?>';
    ?>
    Ex. Script 2 - File name is 'script_2.php' at http://www.server_b.com
    PHP Code:
    <?php
      
    include 'http://www.server_a.com/script_1.php';
    ?>
    Results would be:
    Code:
    hello world
    What happens when you do not control server_a is the person who does control it now controls yours as well which is why it is not recommended that you do this. Truthfully they could erase your entire server if they are good enough.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •