I have two PHP files located on different servers, one at http://www.mysite.com/main.php, the other at http://www.sample.com/includeThis.php.
I want to include the second file from the first one.
The content of the second file looks like this:
<?php
$foo = "this is data from file one";
And the first file:
<?php
include "http://www.sample.com/includeThis.php";
echo $foo;
Is there any way I can do this?
Nope, this setting is disabled/not allowed by default in most web servers (php.ini) so you can not use the
includeto include the files from a remote addresss for security reasons.If you still want to allow inclusion of remote files, the directive
allow_url_includemust be set toOnin php.iniBut again it is a bad practice, in a security-oriented point of view ; and, so, it is generally disabled (I’ve never seen it enabled, actually)
If you want to read the contents of a remote file though, you can use the
file_get_contentsfunction instead BUT this will be returned as pure HTML markup code, there won’t be any server-side code.