PHP在不同服务器/主机上的主域的子域中包含一个文件 [英] PHP include a file at subdomain from main domain on a different server/host
本文介绍了PHP在不同服务器/主机上的主域的子域中包含一个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个php
www.example.com/template.php
并希望将其包含在index.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.
推荐答案
你可以下载将文件内容放入php文件,然后包括,
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;
我建议从index.php更改名称,并确保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.
这也没什么安全的。
编辑:另一个选项,
有一个名为allow_url_include的php.ini选项。
There is a php.ini option called allow_url_include.
http://php.net/manual/en/features.remote-files.php
这篇关于PHP在不同服务器/主机上的主域的子域中包含一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文