我曾常常在网站之间包含文件,直到我的webhost禁止练习。现在看来,最近的PHP升级也收紧了螺丝,因为我得到了一个"没有找到合适的包装纸#34;错误 - 我正在使用LOCAL网站。
让我们从@ www.gx.com网站和subdomain.mysite.com上的子域开始。但是,它们在本地显示为两个独立的网站 - mysite.com和subdomain.com。
subdomain.com上的页面包含以下包含请求:
require_once($GX_URL."/2b/inc/D/Shared/Body/Bottom/Footer.php
$ GX_URL在本地显示为http [://] gx,在线显示http [://] gx.com。
如何修改此包含以便它在两种情况下都有效?我可以使用以下开关来保存两个单独的包含,一个用于在线使用,另一个用于本地使用:
switch(PHP_OS)
{
case 'Linux':
break;
default:
break;
}
我刚刚想出了第一个问题的答案;我只是将我计算机上其他网站中文件的整个路径映射出来: /Applications/MAMP/htdocs/gx/2b/inc/D/Shared/Body/Bottom/Footer.php
所以我想我需要做类似的事情来包含我的主域名中的文件。但是,如果有人有更优雅的解决方案,我会保留这个问题。
答案 0 :(得分:1)
我有更多你可以尝试一个。
尝试下载html并包含到您的php页面:)。
使用 Allow_url_include ,例如:http://wiki.dreamhost.com/Allow_url_include
示例::
<强> 1。卷曲下载html字符串
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发送请求宽度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\r\n" . "Content-Length: " . strlen($data) . "\r\n",
'content' => $data)
);
$context = stream_context_create($context_options);
$result = file_get_contents($url, false, $context);
return $result;
}