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 组策略中的计算机配置策略无法下发
  • ¥15 机器学习简单问题解决
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写