...

View Full Version : Question about PHP Includes



millsi80
09-11-2009, 01:26 AM
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

Zangeel
09-11-2009, 02: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().

millsi80
09-11-2009, 03:18 AM
Ah, alright thanks

Coyote6
09-11-2009, 08: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


<?php
echo '<?php echo "hello world"; ?>';
?>


Ex. Script 2 - File name is 'script_2.php' at http://www.server_b.com


<?php
include 'http://www.server_a.com/script_1.php';
?>


Results would be:


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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum