09-11-2009, 12:26 AM
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.
09-11-2009, 01:12 AM
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().
09-11-2009, 07:10 PM
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
echo '<?php echo "hello world"; ?>';
Ex. Script 2 - File name is 'script_2.php' at http://www.server_b.com
Results would be:
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.