【问题标题】:Loading a website from another doesn't load css从另一个网站加载网站不会加载 css
【发布时间】:2018-09-17 08:09:57
【问题描述】:

客户想要从他的网站加载我的网站功能,所以我正在创建一个 php 脚本,该脚本使用 curl 加载我的网站,将所有请求重定向到我的网站,但如果 html 代码似乎已正确加载并且 css 文件也是,css里面的样式没有加载。

我不明白为什么。

脚本:

<?php
$uri=preg_replace('#[^a-z0-9_?\./|=]#','',$_SERVER['REQUEST_URI']);

set_time_limit(3600);

$cs=curl_init();

curl_setopt($cs, CURLOPT_RETURNTRANSFER, 1);    
curl_setopt($cs, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($cs, CURLOPT_SSL_VERIFYHOST, 0);

curl_setopt($cs, CURLOPT_COOKIEFILE, "../some.cookies");
curl_setopt($cs, CURLOPT_COOKIEJAR, "../some.cookies");

curl_setopt($cs, CURLOPT_HTTPGET, 1);
curl_setopt($cs, CURLOPT_ACCEPT_ENCODING, "gzip");

curl_setopt($cs, CURLOPT_URL, "https://mydomain.tld".$uri);

curl_setopt($cs, CURLOPT_POSTFIELDS, $_POST);
curl_setopt($cs, CURLOPT_POST, count($_POST)>0);

print curl_exec($cs);   

curl_close($cs);

【问题讨论】:

  • 检查元素时会发现以下警告信息。 Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://linkall.arcadia.services/base.css?v1536047306".
  • 在网上搜索上述错误信息,了解如何解决。
  • @SauminiNavaratnam 你说得对,我必须添加 mime 类型,谢谢。

标签: php curl


【解决方案1】:

必须添加 Mime 类型,这是工作代码:

set_time_limit(3600);

$cs=curl_init();

    curl_setopt($cs, CURLOPT_RETURNTRANSFER, 1);    
    curl_setopt($cs, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($cs, CURLOPT_SSL_VERIFYHOST, 0);

    curl_setopt($cs, CURLOPT_COOKIEFILE, "../some.cookies");
    curl_setopt($cs, CURLOPT_COOKIEJAR, "../some.cookies");

    curl_setopt($cs, CURLOPT_HTTPGET, 1);
    curl_setopt($cs, CURLOPT_ACCEPT_ENCODING, "gzip");

    curl_setopt($cs, CURLOPT_URL, "https://mydomain.tld".$uri);

    curl_setopt($cs, CURLOPT_POSTFIELDS, http_build_query($_POST));
    curl_setopt($cs, CURLOPT_POST, count($_POST)>0);

    $html=curl_exec($cs);   
    $mime=curl_getinfo($cs, CURLINFO_CONTENT_TYPE);

    header("Content-Type: $mime");
    print $html;

curl_close($cs);

【讨论】:

    猜你喜欢
    • 2020-10-18
    • 1970-01-01
    • 1970-01-01
    • 2018-11-09
    • 1970-01-01
    • 1970-01-01
    • 2014-02-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多