function get_proxy()
{
global $proxies;
$proxies = [];
foreach (file(getcwd() . '/../../proxy.txt') as $str)
{
$str = trim($str);
if (strpos($str, ':') === false) continue;
$proxies[] = $str;
}
if ( ! sizeof($proxies)) return false;
shuffle($proxies);
print_r($proxies);
return array_pop($proxies);
}
function remove_proxy()
{
global $proxies;
unset($proxies[array_search($_SESSION['proxy'], $proxies)]);
file_put_contents(getcwd() . '/../../proxy.txt', join("\n", $proxies), LOCK_EX);
print_r($proxies);
$_SESSION['proxy'] = null;
}
function curl($url)
{
global $config;
if (empty($_SESSION['proxy']))
{
$_SESSION['proxy'] = get_proxy();
echo $_SESSION['proxy'];
}
static $ch = null;
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, false );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
if ($_SESSION['proxy'])
{
curl_setopt($ch, CURLOPT_PROXY, $_SESSION['proxy']);
curl_setopt($ch, CURLOPT_PROXYTYPE, $config['proxy_type']);
}
$response = curl_exec( $ch );
if ($_SESSION['proxy'])
{
if (curl_getinfo($ch, CURLINFO_RESPONSE_CODE) > 399 || strlen($response) > 100 || empty($response))
{
remove_proxy();
return curl($url);
}
}
curl_close( $ch );
return $response;
}
?>