0

简而言之,我有以下代码:

<html>
<script type="text/javascript">
function getQueryVariable(variable,def) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  }
  return def;
}
function redirect(){
    window.location.href = 'static/popups/'+getQueryVariable('event_id',0)+getQueryVariable('tv_id',0)+getQueryVariable('tid',0)+getQueryVariable('channel',0)+'.html';
} 
</script>
<body onload="redirect()">
<style>body{background-color: #000000; text-align: center;}</style>
</body></html>

window.location.href在上面的代码中将重定向到最终 URL 我想让它不重定向,而是在新的 CUrl 函数中使用这个最终 URL 来获取它的源代码。

到现在 3 个小时,我想不通。

我将用来获取最终 url 源代码的代码是:

<?php
    //Get the url
    $url = "the final url";

    //Get the html of url
    function get_data($url) 
    { 
       $ch = curl_init();
       $timeout = 5;
       //$userAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US)AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.X.Y.Z Safari/525.13.";
       $userAgent = "IE 7 – Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30)";
      curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
      curl_setopt($ch, CURLOPT_FAILONERROR, true);
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
      curl_setopt($ch, CURLOPT_AUTOREFERER, true);
      curl_setopt($ch, CURLOPT_TIMEOUT, 10);
      curl_setopt($ch,CURLOPT_URL,$url);
      curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
      curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
      $data = curl_exec($ch);
      curl_close($ch);
      return $data;

    }

    $html = file_get_contents($url);

    echo $html;
?>

我如何将这些合并到功能并集成两者?

4

0 回答 0