Answer the question
In order to leave comments, you need to log in
Why is the page not downloaded on the server, but downloaded from the local one with the same proxy?
$url = 'https://site.ru';
$img = curl_get_contents($url, '', '', 'https://site.ru');
echo $img['code'];
file_put_contents(__DIR__ . '/1.jpg', $img['exec']);
function curl_get_contents($url, $proxy = false, $proxyuserpwd = false, $referer = 'https://www.google.com/', $timeout = 10, $useragent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 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',
'accept-language: ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7,de;q=0.6',
'cache-control: no-cache',
'pragma: no-cache'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_REFERER, $referer);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyuserpwd);
$return['exec'] = curl_exec($ch);
$return['code'] = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
$return['info'] = curl_getinfo($ch);
return $return;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question