卷曲工作在本地主机上合适,但在服务器上不工作

时间:2020-06-28 16:59:29

标签: php curl

现在,我使用curl获取html5player.setVideoUrlLow,并且工作正常,但质量很差。因此,我需要获取html5player.setVideoUrlHigh,但是如果我从服务器运行,则此参数不会显示为curl响应!在本地主机上工作正常!我在代码中缺少什么? 已经尝试过使用不同的CURLOPT_USERAGENT和相同的问题!谢谢!

<?php
function getstring($string,$start,$end)
{
   $str = explode($start,$string);
   $str = explode($end,$str[1]);
   return $str[0];
}

$viewkey = $_GET['viewkey']; // https://mypage.com/view_video.php?viewkey=54501623
$url = "http://www.xvideos.com/embedframe/".$viewkey."";
// $url = "http://www.xvideos.com/video".$viewkey.""; // alternate but same result // 

$curl = curl_init();
$header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,";
$header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
$header[] = "Cache-Control: max-age=0";
$header[] = "Connection: keep-alive";
$header[] = "Keep-Alive: 300";
$header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
$header[] = "Accept-Language: en-us,en;q=0.5";
$header[] = "Pragma: ";

curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) Ap");
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_REFERER, "http://www.google.com/bot.html");
curl_setopt($curl, CURLOPT_ENCODING, "gzip,deflate");
curl_setopt($curl, CURLOPT_AUTOREFERER, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION,true);

$html = curl_exec($curl);
curl_close($curl);

$VideoUrlLow=getstring($html,"html5player.setVideoUrlLow('","');");
$VideoUrlHigh=getstring($html,"html5player.setVideoUrlHigh('","');");

if($VideoUrlHigh!="")
{
   $mp4 = $VideoUrlHigh; // empty on server but work in localhost
} else 
{
   $mp4 = $VideoUrlLow;
}

header('Location: '.$mp4);
?>

0 个答案:

没有答案