$url = 'https://yobit.net/api/3/ticker/ltc_btc-nmc_btc';
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_USERAGENT => '',
CURLOPT_COOKIEJAR => ''
]);
$html = curl_exec($ch);
if (strstr($html, "DDoS protection by CloudFlare")) {
curl_setopt_array($ch, [
CURLOPT_URL => get_jschl($html, $url),
CURLOPT_REFERER => $url
]);
$html = curl_exec($ch);
}
echo $html;
function get_jschl($html, $url)
{
// get var name
// var s,t,o,p,b,r,e,a,k,i,n,g,f, ZKlZkGE={"TRNDyY":+((!+[]+!![]+!![]+[])+(!+[]+!![]+!![]))};
preg_match('~var \S+\s+(\w+)=\{"(\w+)":([^}]+)\}~', $html, $match);
$answer = calc($match[3]);
$pattern = sprintf('~%s\.%s([-+*])=([^;]+)~', $match[1], $match[2]);
preg_match_all($pattern, $html, $matches, PREG_SET_ORDER);
foreach ($matches as $m) {
switch ($m[1]) {
case '-' : $answer -= calc($m[2]); break;
case '+' : $answer += calc($m[2]); break;
case '*' : $answer *= calc($m[2]); break;
}
}
$m = parse_url($url);
preg_match_all('~<input type="hidden" name="([^"]+)" value="([^"]+)~', $html, $matches);
$data = array_combine($matches[1], $matches[2]);
$data['jschl_answer'] = $answer + strlen($m['host']);
sleep(4);
return sprintf('%s://%s/cdn-cgi/l/chk_jschl?%s', $m['scheme'], $m['host'], http_build_query($data));
}
function calc($expr)
{
$result = '';
preg_match_all('~\([^()]+\)~', "($expr)", $matches);
foreach ($matches[0] as $v) {
$result .= substr_count($v, '!+') + substr_count($v, '!![]');
}
return $result;
}