K
K
khodos_dmitry2018-05-05 21:15:42
PHP
khodos_dmitry, 2018-05-05 21:15:42

Why can't curl download this link?

$url = 'https://credits-pl.ru/offer/kredit-911/';
    $curl = curl_init();
    $cookie = __DIR__ .'/cookie/cookie.txt';
    $user_agent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36";
    $headers = [
      'Referer: http://www.google.com/',
      "User-Agent: $user_agent"
    ];
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($curl, CURLOPT_TIMEOUT, 30);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie);
    curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie);
    $str = curl_exec($curl);

I get a server response code of 200. But the link does not follow redirects to the end.
The page with the host mfc911.ru should be parsed, but the redirect does not reach it. The host remains go.leadgid.ru .

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
instocky, 2018-05-07
@instocky

if you are interested in experimenting with the code - then yourself !
if the solution is google.com
here is the first search output

I
ivankomolin, 2018-05-17
@ivankomolin

Add to the code And it will immediately be clear what is happening. If the server returned 200, then it was he who decided that there was no need to do a redirect further.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question