Skip to content Skip to sidebar Skip to footer

Include files from different servers using php

Reading Time: < 1 minute

How to include different files from different servers using PHP? Is this possible easily? Read this to know about this fully.

Many hosting companies preventing php access to outside files.So you can not use the include to include the files from a remote address for security reasons.
If you use normal file including script as follows,

include("http://www.mydomain.com/template.php");

then will displaying errors;
"Warning: include() [function.include]: URL file-access is disabled in the server configuration in www.mydomain.com/template.php on line......" or failed to open stream: Permission denied in....
If you want to include remote files, you must enable allow_url_include setting in the php.ini file.You can do it by adding following line into your page.But this is a bad habit. 😀

 ini_set('allow_url_include', 'On');

If you want to read the contents of a remote file though, you can use the file_get_contents function.But there are no any server side scripts like php. Because it is pure HTML markup code.

$homepage = file_get_contents('http://www.webexplorar.com/');
echo $homepage;