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

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

报告相同问题?

悬赏问题

  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能