Warning: Cannot use a scalar value as an array in /home/admin/public_html/forum/include/fm.class.php on line 757

Warning: Invalid argument supplied for foreach() in /home/admin/public_html/forum/include/fm.class.php on line 770
Форумы портала PHP.SU :: Версия для печати :: Curl выдает ошибку: 403 forbidden
Форумы портала PHP.SU » » Работа с сетью » Curl выдает ошибку: 403 forbidden

Страниц (1): [1]
 

1. qtk - 16 Марта, 2016 - 12:35:40 - перейти к сообщению
При парсинге страницы через Curl выдает ошибку 403 forbidden, а если использовать file_get_contents то все нормально. Парсю http://history[dot]radiorecord[dot]ru/ai[dot][dot][dot]club/2016-03-16/
PHP:
скопировать код в буфер обмена
  1. function curl($url = '', $post = '', $referer = '', $proxy = '')
  2.     {
  3.         $cl = curl_init();
  4.                
  5.         curl_setopt($cl, CURLOPT_URL, $url);
  6.                
  7.         curl_setopt($cl, CURLOPT_RETURNTRANSFER, 1);
  8.                
  9.         curl_setopt($cl, CURLOPT_HEADER, 0);  
  10.                
  11.         curl_setopt($cl, CURLOPT_SSL_VERIFYPEER, 0);
  12.                
  13.         curl_setopt($cl, CURLOPT_SSL_VERIFYHOST, 0);
  14.                
  15.         curl_setopt($cl, CURLOPT_USERAGENT, $this->userAgent);
  16.                
  17.         //curl_setopt($cl, CURLOPT_ENCODING, 'gzip, deflate');
  18.                
  19.                 //curl_setopt($cl, CURLOPT_FOLLOWLOCATION, 0);
  20.                
  21.         curl_setopt($cl, CURLOPT_COOKIEJAR, $this->cookieFile);
  22.                
  23.         curl_setopt($cl, CURLOPT_COOKIEFILE, $this->cookieFile);
  24.        
  25.                 if (isset($post)) {
  26.            
  27.                         curl_setopt($cl, CURLOPT_POST, 1);  
  28.    
  29.             curl_setopt($cl, CURLOPT_POSTFIELDS, $post);
  30.            
  31.                 } else {
  32.        
  33.                     curl_setopt($cl, CURLOPT_POST, 0);
  34.                        
  35.             }
  36.        
  37.         if (isset($referer)) {
  38.        
  39.                     curl_setopt($cl, CURLOPT_REFERER, $referer);
  40.            
  41.                 } else {
  42.        
  43.                     curl_setopt($cl,CURLOPT_REFERER, 1);
  44.                        
  45.             }
  46.        
  47.         if (isset($proxy)) {
  48.        
  49.                 curl_setopt($cl, CURLOPT_PROXY, $proxy);
  50.        
  51.             }
  52.    
  53.         $ex = curl_exec($cl);
  54.                
  55.         //$ex = iconv('cp1251','UTF8',$ex);
  56.                
  57.         curl_close($cl);
  58.        
  59.             return $ex;
  60.     }

 

Powered by ExBB FM 1.0 RC1