I
I
IgorekOzhigov2020-05-15 17:41:28
PHP
IgorekOzhigov, 2020-05-15 17:41:28

The site returns an empty response with cURL, how to solve?

I have a function through which I make a request:

if(!function_exists('request')) {
  function request($method = "GET", $url = null, $params = null, $proxy = null, $proxy_userpwd = null) {
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');;

    if($method == "POST") {
      curl_setopt($ch, CURLOPT_POST, 1);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $params['params']);
    } else {
      curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
    }

    if(isset($params['headers'])) {
      curl_setopt($ch, CURLOPT_HTTPHEADER, $params['headers']);
    }

    if(isset($params['cookies'])) {
      curl_setopt($ch, CURLOPT_COOKIE, $params['cookies']);
    }

    if($proxy) {
      curl_setopt($ch, CURLOPT_PROXY, $proxy);

      if($proxy_userpwd) {
        curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxy_userpwd);
      }
    }

    $result = curl_exec($ch);
    
    $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
    $headers = substr($result, 0, $header_size);
    $content = substr($result, $header_size);
    
    preg_match_all('|Set-Cookie: (.*);|U', $headers, $parse_cookies);
    $cookies = implode(';', $parse_cookies[1]);

    curl_close($ch);

    return array('headers' => $headers, 'cookies' => $cookies, 'content' => $content);
  }
}


Passing headers:
$headers = array();
$headers[] = 'Authority: lolz.guru';
$headers[] = 'DNT: 1';
$headers[] = 'Upgrade-Insecure-Requests: 1';
$headers[] = 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36';
$headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9';
$headers[] = 'Sec-Fetch-Site: none';
$headers[] = 'Sec-Fetch-Mode: navigate';
$headers[] = 'Sec-Fetch-User: ?1';
$headers[] = 'Sec-Fetch-Dest: document';
$headers[] = 'Accept-Language: ru,en;q=0.9,ru-RU;q=0.8,en-US;q=0.7';
$headers[] = 'If-Modified-Since: Fri, 15 May 2020 14:16:00 GMT';


I call the function and get empty content:
$page = request('GET', 'https://lzt.guru/', ['headers' => $headers]);
print_r($page);


The site is protected from parsing, if you know how to solve this problem, you can leave your TG for $$$

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nokimaro, 2020-05-15
@IgorekOzhigov

Add cookies to requests
They are set by the script https://lolz.guru/process-qv9ypsgmv9.js

$headers[] = 'Cookie: df_id=1a27d67187d95fd10605da53ce343bbb';

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question