duanraa1984 2016-02-23 02:26
浏览 58
已采纳

在子域中包含来自主域的文件

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.

  • 写回答

1条回答 默认 最新

  • dtxw20878 2016-02-23 04:04
    关注

    I have more you can try one.

    1. Try download html and include to your php page :).

      • Http Request or CURL request
    2. Use Allow_url_include, example: http://wiki.dreamhost.com/Allow_url_include

    3. 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;
        }
    

    3 Object : http://php.net/manual/de/function.ob-start.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 u盘问题:盘符不显示 无媒体
  • ¥50 R语言读取nc按月均值转为tif
  • ¥30 智能车串级pid调参
  • ¥15 visual studio code翻译老是错误
  • ¥20 卫星测高数据的高程转换
  • ¥15 爬取招聘网站数据信息
  • ¥15 安装完tensorflow,import tensorflow as tf后报错,如何解决?
  • ¥15 ultralytics库导出onnx模型,模型失去预测能力
  • ¥15 linux下点对点协议连接2个USB串口的硬件流量控制问题
  • ¥15 SQL数据自动生成问题