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

自作多情 提交于 2019-12-13 06:26:32

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/13577189/php-include-a-file-at-subdomain-from-main-domain-on-a-different-server-host

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!