在子域中包含来自主域的文件
I used to include files between sites routinely, until my webhost banned the practice. Now it appears that a recent PHP upgrade also tightened the screws, as I'm getting a "no suitable wrapper could be found" error - and I'm working with LOCAL sites.
Let's start with a website @ www.gx.com and a subdomain at subdomain.mysite.com. However, they display locally as two separate websites - mysite.com and subdomain.com.
A page on subdomain.com features the following include request:
require_once($GX_URL."/2b/inc/D/Shared/Body/Bottom/Footer.php
$GX_URL displays as http[://]gx locally and http[://]gx.com online.
How can I modify this include so it works in both situations? I can use the following switch to hold two separate includes, one for online use and the other for local use:
switch(PHP_OS)
{
case 'Linux':
break;
default:
break;
}
I just figured the answer to my first question; I simply mapped out the entire path to the file in the other website on my computer: /Applications/MAMP/htdocs/gx/2b/inc/D/Shared/Body/Bottom/Footer.php
So I guess I need to do something similar to include a file from my main domain. However, I'll leave this question open in case anyone has a more elegant solution.
我曾经常常在网站之间包含文件,直到我的webhost禁止练习。 现在看来最近的PHP升级还收紧了螺丝,因为我得到了“找不到合适的包装器”的错误 - 而且我正在使用LOCAL网站。 p>
让我们看看 从网站@ www.gx.com开始,子网站在subdomain.mysite.com。 但是,它们在本地显示为两个单独的网站 - mysite.com和subdomain.com。 p>
subdomain.com上的页面包含以下包含请求: p>
$ GX_URL显示为http [ ://] gx本地和http [://] gx.com在线。 p>
如何修改此包含以便在两种情况下都能正常工作?我可以使用以下开关来保持 两个单独的包括,一个用于在线使用,另一个用于本地使用: p>
我刚刚想出了第一个问题的答案;我只是在其他网站上绘制了文件的完整路径。 我的电脑:
/Applications/MAMP/htdocs/gx/2b/inc/D/Shared/Body/Bottom/Footer.php 所以我想我需要做类似的事情 包括来自我的主域名的文件。但是,如果有人哈,我会保留这个问题 是一个更优雅的解决方案。 p>
div> require_once($ GX_URL。“/ 2b / inc / D / Shared / Body / Bottom / Footer.php
code> pre>
switch(PHP_OS)
{
case'Linux':
break;
default :
break;
}
code> pre>
I have more you can try one.
-
Try download html and include to your php page :).
- Http Request or CURL request
Use Allow_url_include, example: http://wiki.dreamhost.com/Allow_url_include
Use Object download: http://php.net/manual/de/function.ob-start.php
Example::
1. Curl Download html string
function curl_get($url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERAGENT, $this->CURL_UA);
curl_setopt($ch, CURLOPT_REFERER, $this->YT_BASE_URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$contents = curl_exec ($ch);
curl_close ($ch);
return $contents;
}
2. Http send request width file_get_contents
function sendRequest($url, $data = array())
{
$data = http_build_query($data);
$context_options = array('http' => array('method' => 'POST',
'header' => "Content-type: application/x-www-form-urlencoded
" . "Content-Length: " . strlen($data) . "
",
'content' => $data)
);
$context = stream_context_create($context_options);
$result = file_get_contents($url, false, $context);
return $result;
}