简体   繁体   中英

PHP include a file at subdomain from main domain on a different server/host

I have this php

www.example.com/template.php

and would like to include it in a index.php file at

sub.example.com/index.php

and this sub-domain is on a different server with a different host.

Please advice.

You can download the file contents into a php file then include that,

$url = "http://sub.example.com/index.php";
$file = file_get_contents($url);
file_put_contents('index.php', $file);
include index.php;

I'd recommend changing the name from index.php tho, and make sure the php file isn't being parsed first when you getting it.

There is also nothing safe about this.

Edit: Another option,

There is a php.ini option called allow_url_include.

http://php.net/manual/en/features.remote-files.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM