包含html页面时无法获取输出,出现此错误推荐人策略:no-referrer-when-downgrade

时间:2018-11-16 09:41:30

标签: php html api

我正在调用此页面,并且在检入网络时出现此错误,在浏览器中没有输出。但是,如果我尝试包括简单的html,它就可以工作。

我正在使用此API https://faq.revcontent.com/customer/en/portal/articles/2935349-revcontent-api-documentation---standard-publisher

  

推荐人政策:降级时不推荐人

<!Doctype html>
<html>
<head>
    <title>Index</title>
</head>
<body>  


<div w3-include-html="getAds.php?widget_id=97862&w=160&h=600"></div>

<script>
function includeHTML() {
  var z, i, elmnt, file, xhttp;
  /*loop through a collection of all HTML elements:*/
  z = document.getElementsByTagName("*");
  for (i = 0; i < z.length; i++) {
    elmnt = z[i];
    /*search for elements with a certain atrribute:*/
    file = elmnt.getAttribute("w3-include-html");
    if (file) {
      /*make an HTTP request using the attribute value as the file name:*/
      xhttp = new XMLHttpRequest();
      xhttp.onreadystatechange = function() {
        if (this.readyState == 4) {
          if (this.status == 200) {elmnt.innerHTML = this.responseText;}
          if (this.status == 404) {elmnt.innerHTML = "Page not found.";}
          /*remove the attribute, and call this function once more:*/
          //elmnt.removeAttribute("w3-include-html");          
          //includeHTML();
        }
      } 
      xhttp.open("GET", file, true);
      xhttp.send();
      /*exit the function:*/
      return;
    }
  }
}
includeHTML();
</script>
</body> 
</html>

这是我要包含的PHP页面。

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
include (dirname(__FILE__) . '/MainApi/Main.php');

$domain = "realtimepolitics.com";
$widget_id = $_GET['widget_id']; //97862
$weight = $_GET['w'];
$height = $_GET['h'];

$sponsored_count = 500;
$internal_offset = 1;
$sponsored_offset = 0;
$internal_count = 3;
$user_ip = $_SERVER['REMOTE_ADDR']?:($_SERVER['HTTP_X_FORWARDED_FOR']?:$_SERVER['HTTP_CLIENT_IP']);
$user_agent = $_SERVER['HTTP_USER_AGENT'];
$main = new MainApi\Main($domain, $widget_id, $sponsored_count, $internal_offset, $sponsored_offset, $internal_count,$user_ip, $user_agent);
$response = $main->getResponse();
$ad_data = json_decode($response);

$adsCount = count($ad_data);
$key = array_rand($ad_data,1);
$ads_data = $ad_data[$key];

switch ($weight)
{
case "160":
    if ($height == "600"):
        include (dirname(__FILE__) . '/ad_samples/Ad_' . $weight . 'x' . $height . '/index.php');

    else:
        echo "Error: Invalid Height Attribute";
    endif;
    break;

case "300":
    if ($height == "250"):
        include (dirname(__FILE__) . '/ad_samples/Ad_' . $weight . 'x' . $height . '/index.php');

    elseif ($height == "50"):
        include (dirname(__FILE__) . '/ad_samples/Ad_' . $weight . 'x' . $height . '/index.php');

    else:
        echo "Error: Invalid Height Attribute";
    endif;
    break;

case "320":
    if ($height == "50"):
        include (dirname(__FILE__) . '/ad_samples/Ad_' . $weight . 'x' . $height . '/index.php');

    else:
        echo "Error: Invalid Height Attribute";
    endif;
    break;

case "480":
    if ($height == "120"):
        include (dirname(__FILE__) . '/ad_samples/Ad_' . $weight . 'x' . $height . '/index.php');

    else:
        echo "Error: Invalid Height Attribute";
    endif;
    break;

case "728":
    if ($height == "90"):
        include (dirname(__FILE__) . '/ad_samples/Ad_' . $weight . 'x' . $height . '/index.php');

    else:
        echo "Error: Invalid Height Attribute";
    endif;
    break;

default:
    echo "Error: Invalid Height & Width Attribute";

echo $html; 
} ?>

0 个答案:

没有答案