K
K
khodos_dmitry2017-04-21 18:16:59
PHP
khodos_dmitry, 2017-04-21 18:16:59

Why can't I parse a site with a proxy?

It's parsed without a proxy, but not with a proxy.
<?php
// ini_set('max_execution_time', '60');
set_time_limit(600);
ini_set('memory_limit', '2048M');
ignore_user_abort(true);
require_once('functions/proxy/getproxy.php');
$link = mysqli_connect('localhost', 'root', '', 'driver1');
$proxy = getproxy();
$proxy_host = $proxy['host'];
$proxy_id = $proxy['id'];
$proxy_port = $proxy['port'];
$proxy_username = $proxy['username'];
$proxy_pass = $proxy['pass'];
$user_agent = $proxy['user-agent'];
$url = " credits-pl.ru ";
$curl = curl_init();
$cookie = __MYDIR__ .'/cookie/cookie.txt';
$headers = [
"Referer: yandex.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_PROXY, "$proxy_host:$proxy_port");
curl_setopt($curl, CURLOPT_HTTPPROXYTUNNEL, 1);
// curl_setopt($curl, CURLOPT_PROXYUSERPWD, "$proxy_username:$proxy_pass");
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
curl_setopt($curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
$str = curl_exec($curl);
if (curl_getinfo($curl, CURLINFO_HTTP_CODE) == 200) {
echo $str;
}
else {
echo "Failed to download page $url";
$query = "UPDATE `proxy` SET `banned` = '1' WHERE `host` = '$proxy_host'";
mysqli_query($link, $query) or die("Can't update proxy: ".mysqli_error($link));
}
?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Kiselyov, 2017-04-22
@zamboga

Proxy in the bath

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question