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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵