Если вы немного подправите свою функцию, добавив port
, она будет работать нормально
function get_page( $url, $proxy = false, $port=false ){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 200);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
if( !empty( $proxy ) && !empty( $port ) ){
curl_setopt($ch, CURLOPT_PROXY, $proxy );
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 0 );
curl_setopt($ch, CURLOPT_PROXYPORT, $port );
}
curl_setopt($ch, CURLOPT_MAXREDIRS, 2);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7");
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_ENCODING, "gzip");
$data = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
return $data;
}
Используя тот же URL-адрес, который вы дали, но другой прокси и порт
$url='https://hidester.com/what-is-my-ip-address/';
$proxy='137.74.144.21';
$port=8080;
И вызывать так:
<code>$res=get_page( $url, $proxy, $port );
printf('<pre>%s
', print_r ($ res, true));
Использование другой функции curl
с дополнительными опциями для подробного вывода может помочь вам определить, связана ли проблема с хостингом GoDaddy или нет. Если вы скачаете копию cacert.pem
и отредактируете путь ниже, вы должны получить более подробную информацию о запросе.
<code><?php
function curl( $url=NULL, $options=NULL, $headers=false ){
$cacert='c:/wwwroot/cacert.pem';
$vbh = fopen('php://temp', 'w+');
/* get cacert.pem from here */
/* https://curl.haxx.se/docs/caextract.html */
$res=array(
'response' => NULL,
'info' => array( 'http_code' => 100 ),
'headers' => NULL,
'errors' => NULL
);
if( is_null( $url ) ) return (object)$res;
session_write_close();
$curl=curl_init();
if( parse_url( $url,PHP_URL_SCHEME )=='https' ){
curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, true );
curl_setopt( $curl, CURLOPT_SSL_VERIFYHOST, 2 );
curl_setopt( $curl, CURLOPT_CAINFO, $cacert );
}
curl_setopt( $curl, CURLOPT_URL,trim( $url ) );
curl_setopt( $curl, CURLOPT_AUTOREFERER, true );
curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $curl, CURLOPT_FAILONERROR, true );
curl_setopt( $curl, CURLOPT_HEADER, false );
curl_setopt( $curl, CURLINFO_HEADER_OUT, false );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $curl, CURLOPT_BINARYTRANSFER, true );
curl_setopt( $curl, CURLOPT_CONNECTTIMEOUT, 20 );
curl_setopt( $curl, CURLOPT_TIMEOUT, 60 );
curl_setopt( $curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36' );
curl_setopt( $curl, CURLOPT_MAXREDIRS, 10 );
curl_setopt( $curl, CURLOPT_ENCODING, '' );
curl_setopt( $curl, CURLOPT_VERBOSE, true );
curl_setopt( $curl, CURLOPT_NOPROGRESS, true );
curl_setopt( $curl, CURLOPT_STDERR, $vbh );
if( isset( $options ) && is_array( $options ) ){
foreach( $options as $param => $value ) curl_setopt( $curl, $param, $value );
}
if( $headers && is_array( $headers ) ){
curl_setopt( $curl, CURLOPT_HTTPHEADER, $headers );
}
$res=(object)array(
'response' => curl_exec( $curl ),
'info' => (object)curl_getinfo( $curl ),
'errors' => curl_error( $curl )
);
rewind( $vbh );
$res->verbose=stream_get_contents( $vbh );
fclose( $vbh );
curl_close( $curl );
return $res;
}
$url='https://hidester.com/what-is-my-ip-address/';
$url='https://www.whatismyip.com/';
$url='https://api.ipify.org?format=json';
$proxy='137.74.144.21';
$port=8080;
$options=array(
CURLOPT_PROXY => $proxy,
CURLOPT_PROXYPORT => $port,
CURLOPT_HTTPPROXYTUNNEL => true
);
$res=curl( $url, $options );
if( $res->info->http_code==200 ){
printf('<pre>%s
', print_r ($ res-> response, true)); Е ( '
%s
', print_r ($ res-> многословным, правда)); Е ( '
%s
', print_r $ res-> Информация о (, правда)); }?>