За последние 24 часа нас посетили 22596 программистов и 1595 роботов. Сейчас ищут 893 программиста ...

Теле2 свитер

Тема в разделе "Прочее", создана пользователем georgela, 13 янв 2013.

  1. igordata

    igordata Суперстар
    Команда форума Модератор

    С нами с:
    18 мар 2010
    Сообщения:
    32.408
    Симпатии:
    1.768
  2. r3l0c

    r3l0c Активный пользователь

    С нами с:
    10 янв 2013
    Сообщения:
    453
    Симпатии:
    4
    На плагины к хрому можно через настройки зайти, "Расширения->установка расширений"
     
  3. georgela

    georgela Активный пользователь

    С нами с:
    11 май 2011
    Сообщения:
    395
    Симпатии:
    0
    igordata
    Он столько же заголовков выдал что и стандартный мозилловский
     
  4. igordata

    igordata Суперстар
    Команда форума Модератор

    С нами с:
    18 мар 2010
    Сообщения:
    32.408
    Симпатии:
    1.768
    и столько же запросов?
     
  5. georgela

    georgela Активный пользователь

    С нами с:
    11 май 2011
    Сообщения:
    395
    Симпатии:
    0
    igordata
    Да,мой класс все тоже самое в отладчике делает,можешь посмотреть в нетбинсе под хдебаг.Снупи класс везде почти скачать можно вроде
    Поэтому тему и создал что непонятно из за чего 2 разных ответа в браузере и снупи,когда все запросы 1 в 1 сдедуют.
     
  6. igordata

    igordata Суперстар
    Команда форума Модератор

    С нами с:
    18 мар 2010
    Сообщения:
    32.408
    Симпатии:
    1.768
    блин, ну не смогу я посмотреть =) ну не найду времени, прости.
     
  7. georgela

    georgela Активный пользователь

    С нами с:
    11 май 2011
    Сообщения:
    395
    Симпатии:
    0
    igordata
    Там всего 2 пакета,как он определяет что голосует не пользователь если первый 500 ошибку выдает и его не выполняю а второй нормальный но тело ответа с матюгами?
     
  8. georgela

    georgela Активный пользователь

    С нами с:
    11 май 2011
    Сообщения:
    395
    Симпатии:
    0
    Основной запрос содержит заголовок
    Text-encoding:chunked
    И первый заголовок который получает курс это 100 Continue
    Потом уже 200 ОК
    Может быть что курл не совсем адекватно с чанками работает?
    ДОстать кучу левых акков на пару с прокси не особо сложно,программировать думать надо

    Добавлено спустя 2 минуты 28 секунд:
    Если получать результат так : $res= $s->results;
    res будет неопределен,или содержать нул
    Если посмотреть что содержится в переменной $s->results будет написано еррор
    Причем res получается даже если ответ-пустая строка
    В error снупи класса находится Invalid protocol

    Добавлено спустя 45 минут 30 секунд:
    http://vk.com/teletwoclub
    Потому что у меня группа есть,хочу свитер!
     
  9. georgela

    georgela Активный пользователь

    С нами с:
    11 май 2011
    Сообщения:
    395
    Симпатии:
    0
    Вокруг чего был шум
    Код (Text):
    1. <?php
    2. class Tele2{
    3. private $s;
    4. private $t2s;
    5. private $token;
    6.  
    7. public function tele2Golos($id,$proxy='',$port=80){
    8. $s=&$this->t2s;    
    9. if(!empty($proxy)){
    10. $s->proxy_host=$proxy;    
    11. $s->proxy_host=$port;}  
    12. $s->fetch("http://sviter.tele2.ru/sweater/$id");
    13. $s->setcookies();
    14. $s->cookies["vk_token"]=$this->token;
    15. $s->fetch("http://sviter.tele2.ru/voting/verify_tokens/?fb_token=&vk_token=".$this->token."&ok_token=&my_token=");
    16. $s->setcookies();
    17. $vote=array();
    18. $vote['token']=$this->token;
    19. $s->submit("http://sviter.tele2.ru/voting/vote/$id/",$vote);
    20. $s->setcookies();
    21. $res=$this->results;
    22. return false;
    23. }
    24.  
    25. public function sviterToken($id,$proxy='',$port=80){
    26. $s=&$this->s;
    27. $s->maxredirs=0;
    28. $s->fetch("http://oauth.vk.com/authorize?client_id=3295213&redirect_uri=http://sviter.tele2.ru/voting/create_social_user/?social_network=vk");
    29. $s->setcookies();
    30. $res=$s->results;
    31. $headers=$s->headers;$loc="";
    32. foreach($headers as $v){
    33. if(substr($v,0,8)=="Location"){$loc=trim(substr($v,9));break;}    
    34. };
    35. if(empty($loc)){
    36. $pos=strpos($res,"https://login.vk.com/?act=grant_access");
    37. $end=strpos($res,'"',$pos+4);
    38. $c=$end-$pos;
    39. $loc=trim(substr($res,$pos,$c),'"');
    40. }
    41. $loc=urldecode($loc);
    42. //$loc=  str_replace("https", "http", $loc);
    43.  
    44. $cl=curl_init();
    45. curl_setopt($cl, CURLOPT_SSL_VERIFYPEER, false);
    46. curl_setopt($cl, CURLOPT_SSL_VERIFYHOST, false);
    47. curl_setopt($cl, CURLOPT_URL,$loc);
    48. curl_setopt($cl, CURLOPT_HEADER,true);
    49. $cookie="";
    50. foreach($s->cookies as $k=>$v){
    51. if(!empty($cookie))$cookie.="; ";
    52. $cookie.="$k=$v";
    53. }
    54. curl_setopt($cl, CURLOPT_COOKIE, $cookie);
    55. curl_setopt($cl,CURLOPT_RETURNTRANSFER, 1);
    56. $res=  curl_exec($cl);
    57. curl_close($cl);
    58. $headers=str_replace("\r", "", $res);
    59. $headers=explode("\n",$headers);
    60. foreach($headers as $v){
    61. if(substr($v,0,8)=="Location"){$loc=trim(substr($v,9));break;}    
    62. }
    63. //$s=&$this->t2s;
    64. //$s->referer="http://sviter.tele2.ru/sweater/$id";
    65. //$s->fetch("http://sviter.tele2.ru/sweater/$id");
    66. //$s->setcookies();
    67. if(!empty($proxy)){
    68. $s->proxy_host=$proxy;    
    69. $s->proxy_host=$port;}  
    70. $s->fetch($loc);
    71.  
    72. $s->setcookies();
    73. $res=$s->results;
    74. $token=$s->cookies["vk_token"];
    75. if(empty($token))return -1;
    76. $this->token=$token;
    77.  
    78. $s->fetch("http://sviter.tele2.ru/sweater/$id");
    79. $s->setcookies();
    80. $s->referer="http://sviter.tele2.ru/sweater/$id";
    81. $s->fetch("http://sviter.tele2.ru/voting/verify_tokens/?fb_token=&vk_token=".$this->token."&ok_token=&my_token=");
    82. $res=$s->results;
    83. $s->setcookies();
    84. $vote=array();
    85. $vote['token']=$this->token;
    86. $s->referer="http://sviter.tele2.ru/sweater/$id";
    87. $cookie="";
    88. foreach($s->cookies as $k=>$v){
    89. if(!empty($cookie))$cookie.="; ";
    90. $cookie.="$k=$v";
    91. }/*
    92. $cl=curl_init();
    93. curl_setopt($cl, CURLOPT_URL, "http://sviter.tele2.ru/voting/vote/$id/");
    94. curl_setopt($cl, CURLOPT_COOKIE, $cookie);
    95. curl_setopt($cl, CURLOPT_HEADER,true);
    96. curl_setopt($cl,CURLOPT_RETURNTRANSFER, 1);
    97. curl_setopt($cl,CURLOPT_POST, 0);
    98. curl_setopt($cl,CURLOPT_, 1);
    99. curl_setopt($cl,CURLOPT_POSTFIELDS, $vote);
    100. $res=curl_exec($cl);
    101. curl_close($cl);
    102. */
    103. $s->submit("http://sviter.tele2.ru/voting/vote/$id/",$vote);
    104. $s->setcookies();
    105. $res=$this->results;
    106. return false;
    107.  
    108.  
    109. return 1;
    110. }
    111.  
    112. public function loginVK($email,$pass,$proxy='',$port=80){
    113. $s=&$this->s;
    114. if(!empty($proxy)){
    115. $s->proxy_host=$proxy;    
    116. $s->proxy_host=$port;}    
    117. $s->fetch("http://vk.com");
    118. $s->setcookies();
    119. $res=$s->results;
    120. $pos=strpos($res,"ip_h");
    121. $b=strpos($res,"'",$pos+1)+1;
    122. $e=strpos($res,"'",$b);
    123. $c=$e-$b;
    124. $ip_h=trim(substr($res,$b,$c),"'");
    125. $pass=iconv("UTF-8","windows-1251",$pass);
    126. $login=array();
    127. $login["act"]="login";
    128. $login["role"]="al_frame";
    129. $login["_origin"]="http://vk.com";
    130. $login["email"]=$email;
    131. $login["pass"]=$pass;
    132. $login['captcha_sid']="";    
    133. $login['captcha_key']="";    
    134. $login['expire']="";    
    135. $login['ip_h']=$ip_h;    
    136. $s->submit("http://login.vk.com/?act=login",$login);
    137. $s->setcookies();
    138. $id=$s->cookies["l"];
    139. if(empty($id))return -1;
    140. $s->fetch("http://m.vk.com/id$id");
    141. $res=$s->results;
    142. $pos=strpos($res,"prof_info");
    143. if(!$pos)return -2;
    144. return 1;
    145. }
    146.  
    147. public function __construct(){
    148. $s=&$this->s;
    149. $s=new Snoopy();
    150. $s->agent="5.0.5 (6533.21.1, r84622) — Mozilla/5.0 (Macintosh; I; Intel Mac OS X 10_6_7; en-EN) ";
    151. $t2s=&$this->t2s;
    152. $t2s=new Snoopy();
    153. $t2s->agent="5.0.5 (6533.21.1, r84622) — Mozilla/5.0 (Macintosh; I; Intel Mac OS X 10_6_7; en-EN) ";
    154. $t2s->curl_path="C:\Program Files (x86)\PHP\ext\php_curl.php";
    155. $t2s->host="sviter.tele2.ru";
    156. }
    157.  
    158.  
    159.  
    160. }  
    161. ?>
    Код (Text):
    1.  
    2. include("Snoopy.class.php");
    3. include 'Tele2.class.php';
    4. $tele2=new Tele2();
    5. $res=$tele2->loginVK("79066543317", "timati");
    6. $tele2->sviterToken(37406);
    7. //$tele2->tele2Golos(37308);
    8. echo $res;
    Снупи класс
    Код (Text):
    1.  
    2. <?php
    3.  
    4. /*************************************************
    5.  
    6. Snoopy - the PHP net client
    7. Author: Monte Ohrt <monte@ispi.net>
    8. Copyright (c): 1999-2008 New Digital Group, all rights reserved
    9. Version: 1.2.4
    10.  
    11.  * This library is free software; you can redistribute it and/or
    12.  * modify it under the terms of the GNU Lesser General Public
    13.  * License as published by the Free Software Foundation; either
    14.  * version 2.1 of the License, or (at your option) any later version.
    15.  *
    16.  * This library is distributed in the hope that it will be useful,
    17.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    18.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    19.  * Lesser General Public License for more details.
    20.  *
    21.  * You should have received a copy of the GNU Lesser General Public
    22.  * License along with this library; if not, write to the Free Software
    23.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    24.  
    25. You may contact the author of Snoopy by e-mail at:
    26. monte@ohrt.com
    27.  
    28. The latest version of Snoopy can be obtained from:
    29. http://snoopy.sourceforge.net/
    30.  
    31. *************************************************/
    32.  
    33. class Snoopy
    34. {
    35.     /**** Public variables ****/
    36.    
    37.     /* user definable vars */
    38.  
    39.     var $host           =   "www.php.net";      // host name we are connecting to
    40.     var $port           =   80;                 // port we are connecting to
    41.     var $proxy_host     =   "";                 // proxy host to use
    42.     var $proxy_port     =   "";                 // proxy port to use
    43.     var $proxy_user     =   "";                 // proxy user to use
    44.     var $proxy_pass     =   "";                 // proxy password to use
    45.    
    46.     var $agent          =   "Snoopy v1.2.4";    // agent we masquerade as
    47.     var $referer        =   "";                 // referer info to pass
    48.     var $cookies        =   array();            // array of cookies to pass
    49.                                                 // $cookies["username"]="joe";
    50.     var $rawheaders     =   array();            // array of raw headers to send
    51.                                                 // $rawheaders["Content-type"]="text/html";
    52.  
    53.     var $maxredirs      =   5;                  // http redirection depth maximum. 0 = disallow
    54.     var $lastredirectaddr   =   "";             // contains address of last redirected address
    55.     var $offsiteok      =   true;               // allows redirection off-site
    56.     var $maxframes      =   0;                  // frame content depth maximum. 0 = disallow
    57.     var $expandlinks    =   true;               // expand links to fully qualified URLs.
    58.                                                 // this only applies to fetchlinks()
    59.                                                 // submitlinks(), and submittext()
    60.     var $passcookies    =   true;               // pass set cookies back through redirects
    61.                                                 // NOTE: this currently does not respect
    62.                                                 // dates, domains or paths.
    63.    
    64.     var $user           =   "";                 // user for http authentication
    65.     var $pass           =   "";                 // password for http authentication
    66.    
    67.     // http accept types
    68.     var $accept         =   "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*";
    69.    
    70.     var $results        =   "";                 // where the content is put
    71.        
    72.     var $error          =   "";                 // error messages sent here
    73.     var $response_code  =   "";                 // response code returned from server
    74.     var $headers        =   array();            // headers returned from server sent here
    75.     var $maxlength      =   500000;             // max return data length (body)
    76.     var $read_timeout   =   0;                  // timeout on read operations, in seconds
    77.                                                 // supported only since PHP 4 Beta 4
    78.                                                 // set to 0 to disallow timeouts
    79.     var $timed_out      =   false;              // if a read operation timed out
    80.     var $status         =   0;                  // http request status
    81.  
    82.     var $temp_dir       =   "/tmp";             // temporary directory that the webserver
    83.                                                 // has permission to write to.
    84.                                                 // under Windows, this should be C:\temp
    85.  
    86.     var $curl_path      =   "/usr/local/bin/curl";
    87.                                                 // Snoopy will use cURL for fetching
    88.                                                 // SSL content if a full system path to
    89.                                                 // the cURL binary is supplied here.
    90.                                                 // set to false if you do not have
    91.                                                 // cURL installed. See http://curl.haxx.se
    92.                                                 // for details on installing cURL.
    93.                                                 // Snoopy does *not* use the cURL
    94.                                                 // library functions built into php,
    95.                                                 // as these functions are not stable
    96.                                                 // as of this Snoopy release.
    97.    
    98.     /**** Private variables ****/  
    99.    
    100.     var $_maxlinelen    =   4096;               // max line length (headers)
    101.    
    102.     var $_httpmethod    =   "GET";              // default http request method
    103.     var $_httpversion   =   "HTTP/1.0";         // default http request version
    104.     var $_submit_method =   "POST";             // default submit method
    105.     var $_submit_type   =   "application/x-www-form-urlencoded";    // default submit type
    106.     var $_mime_boundary =   "";                 // MIME boundary for multipart/form-data submit type
    107.     var $_redirectaddr  =   false;              // will be set if page fetched is a redirect
    108.     var $_redirectdepth =   0;                  // increments on an http redirect
    109.     var $_frameurls     =   array();            // frame src urls
    110.     var $_framedepth    =   0;                  // increments on frame depth
    111.    
    112.     var $_isproxy       =   false;              // set if using a proxy server
    113.     var $_fp_timeout    =   30;                 // timeout for socket connection
    114.  
    115. /*======================================================================*\
    116.     Function:   fetch
    117.     Purpose:    fetch the contents of a web page
    118.                 (and possibly other protocols in the
    119.                 future like ftp, nntp, gopher, etc.)
    120.     Input:      $URI    the location of the page to fetch
    121.     Output:     $this->results  the output text from the fetch
    122. \*======================================================================*/
    123.  
    124.     function fetch($URI)
    125.     {
    126.    
    127.         //preg_match("|^([^:]+)://([^:/]+)(:[\d]+)*(.*)|",$URI,$URI_PARTS);
    128.         $URI_PARTS = parse_url($URI);
    129.         if (!empty($URI_PARTS["user"]))
    130.             $this->user = $URI_PARTS["user"];
    131.         if (!empty($URI_PARTS["pass"]))
    132.             $this->pass = $URI_PARTS["pass"];
    133.         if (empty($URI_PARTS["query"]))
    134.             $URI_PARTS["query"] = '';
    135.         if (empty($URI_PARTS["path"]))
    136.             $URI_PARTS["path"] = '';
    137.                
    138.         switch(strtolower($URI_PARTS["scheme"]))
    139.         {
    140.             case "http":
    141.                 $this->host = $URI_PARTS["host"];
    142.                 if(!empty($URI_PARTS["port"]))
    143.                     $this->port = $URI_PARTS["port"];
    144.                 if($this->_connect($fp))
    145.                 {
    146.                     if($this->_isproxy)
    147.                     {
    148.                         // using proxy, send entire URI
    149.                         $this->_httprequest($URI,$fp,$URI,$this->_httpmethod);
    150.                     }
    151.                     else
    152.                     {
    153.                         $path = $URI_PARTS["path"].($URI_PARTS["query"] ? "?".$URI_PARTS["query"] : "");
    154.                         // no proxy, send only the path
    155.                         $this->_httprequest($path, $fp, $URI, $this->_httpmethod);
    156.                     }
    157.                    
    158.                     $this->_disconnect($fp);
    159.  
    160.                     if($this->_redirectaddr)
    161.                     {
    162.                         /* url was redirected, check if we've hit the max depth */
    163.                         if($this->maxredirs > $this->_redirectdepth)
    164.                         {
    165.                             // only follow redirect if it's on this site, or offsiteok is true
    166.                             if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok)
    167.                             {
    168.                                 /* follow the redirect */
    169.                                 $this->_redirectdepth++;
    170.                                 $this->lastredirectaddr=$this->_redirectaddr;
    171.                                 $this->fetch($this->_redirectaddr);
    172.                             }
    173.                         }
    174.                     }
    175.  
    176.                     if($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0)
    177.                     {
    178.                         $frameurls = $this->_frameurls;
    179.                         $this->_frameurls = array();
    180.                        
    181.                         while(list(,$frameurl) = each($frameurls))
    182.                         {
    183.                             if($this->_framedepth < $this->maxframes)
    184.                             {
    185.                                 $this->fetch($frameurl);
    186.                                 $this->_framedepth++;
    187.                             }
    188.                             else
    189.                                 break;
    190.                         }
    191.                     }                  
    192.                 }
    193.                 else
    194.                 {
    195.                     return false;
    196.                 }
    197.                 return true;                   
    198.                 break;
    199.             case "https":
    200.                 if(!$this->curl_path)
    201.                     return false;
    202.                 if(function_exists("is_executable"))
    203.                     if (!is_executable($this->curl_path))
    204.                         return false;
    205.                 $this->host = $URI_PARTS["host"];
    206.                 if(!empty($URI_PARTS["port"]))
    207.                     $this->port = $URI_PARTS["port"];
    208.                 if($this->_isproxy)
    209.                 {
    210.                     // using proxy, send entire URI
    211.                     $this->_httpsrequest($URI,$URI,$this->_httpmethod);
    212.                 }
    213.                 else
    214.                 {
    215.                     $path = $URI_PARTS["path"].($URI_PARTS["query"] ? "?".$URI_PARTS["query"] : "");
    216.                     // no proxy, send only the path
    217.                     $this->_httpsrequest($path, $URI, $this->_httpmethod);
    218.                 }
    219.  
    220.                 if($this->_redirectaddr)
    221.                 {
    222.                     /* url was redirected, check if we've hit the max depth */
    223.                     if($this->maxredirs > $this->_redirectdepth)
    224.                     {
    225.                         // only follow redirect if it's on this site, or offsiteok is true
    226.                         if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok)
    227.                         {
    228.                             /* follow the redirect */
    229.                             $this->_redirectdepth++;
    230.                             $this->lastredirectaddr=$this->_redirectaddr;
    231.                             $this->fetch($this->_redirectaddr);
    232.                         }
    233.                     }
    234.                 }
    235.  
    236.                 if($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0)
    237.                 {
    238.                     $frameurls = $this->_frameurls;
    239.                     $this->_frameurls = array();
    240.  
    241.                     while(list(,$frameurl) = each($frameurls))
    242.                     {
    243.                         if($this->_framedepth < $this->maxframes)
    244.                         {
    245.                             $this->fetch($frameurl);
    246.                             $this->_framedepth++;
    247.                         }
    248.                         else
    249.                             break;
    250.                     }
    251.                 }                  
    252.                 return true;                   
    253.                 break;
    254.             default:
    255.                 // not a valid protocol
    256.                 $this->error    =   'Invalid protocol "'.$URI_PARTS["scheme"].'"\n';
    257.                 return false;
    258.                 break;
    259.         }      
    260.         return true;
    261.     }
    262.  
    263. /*======================================================================*\
    264.     Function:   submit
    265.     Purpose:    submit an http form
    266.     Input:      $URI    the location to post the data
    267.                 $formvars   the formvars to use.
    268.                     format: $formvars["var"] = "val";
    269.                 $formfiles  an array of files to submit
    270.                     format: $formfiles["var"] = "/dir/filename.ext";
    271.     Output:     $this->results  the text output from the post
    272. \*======================================================================*/
    273.  
    274.     function submit($URI, $formvars="", $formfiles="")
    275.     {
    276.         unset($postdata);
    277.        
    278.         $postdata = $this->_prepare_post_body($formvars, $formfiles);
    279.            
    280.         $URI_PARTS = parse_url($URI);
    281.         if (!empty($URI_PARTS["user"]))
    282.             $this->user = $URI_PARTS["user"];
    283.         if (!empty($URI_PARTS["pass"]))
    284.             $this->pass = $URI_PARTS["pass"];
    285.         if (empty($URI_PARTS["query"]))
    286.             $URI_PARTS["query"] = '';
    287.         if (empty($URI_PARTS["path"]))
    288.             $URI_PARTS["path"] = '';
    289.  
    290.         switch(strtolower($URI_PARTS["scheme"]))
    291.         {
    292.             case "http":
    293.                 $this->host = $URI_PARTS["host"];
    294.                 if(!empty($URI_PARTS["port"]))
    295.                     $this->port = $URI_PARTS["port"];
    296.                 if($this->_connect($fp))
    297.                 {
    298.                     if($this->_isproxy)
    299.                     {
    300.                         // using proxy, send entire URI
    301.                         $this->_httprequest($URI,$fp,$URI,$this->_submit_method,$this->_submit_type,$postdata);
    302.                     }
    303.                     else
    304.                     {
    305.                         $path = $URI_PARTS["path"].($URI_PARTS["query"] ? "?".$URI_PARTS["query"] : "");
    306.                         // no proxy, send only the path
    307.                         $this->_httprequest($path, $fp, $URI, $this->_submit_method, $this->_submit_type, $postdata);
    308.                     }
    309.                    
    310.                     $this->_disconnect($fp);
    311.  
    312.                     if($this->_redirectaddr)
    313.                     {
    314.                         /* url was redirected, check if we've hit the max depth */
    315.                         if($this->maxredirs > $this->_redirectdepth)
    316.                         {                      
    317.                             if(!preg_match("|^".$URI_PARTS["scheme"]."://|", $this->_redirectaddr))
    318.                                 $this->_redirectaddr = $this->_expandlinks($this->_redirectaddr,$URI_PARTS["scheme"]."://".$URI_PARTS["host"]);                    
    319.                            
    320.                             // only follow redirect if it's on this site, or offsiteok is true
    321.                             if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok)
    322.                             {
    323.                                 /* follow the redirect */
    324.                                 $this->_redirectdepth++;
    325.                                 $this->lastredirectaddr=$this->_redirectaddr;
    326.                                 if( strpos( $this->_redirectaddr, "?" ) > 0 )
    327.                                     $this->fetch($this->_redirectaddr); // the redirect has changed the request method from post to get
    328.                                 else
    329.                                     $this->submit($this->_redirectaddr,$formvars, $formfiles);
    330.                             }
    331.                         }
    332.                     }
    333.  
    334.                     if($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0)
    335.                     {
    336.                         $frameurls = $this->_frameurls;
    337.                         $this->_frameurls = array();
    338.                        
    339.                         while(list(,$frameurl) = each($frameurls))
    340.                         {                                                      
    341.                             if($this->_framedepth < $this->maxframes)
    342.                             {
    343.                                 $this->fetch($frameurl);
    344.                                 $this->_framedepth++;
    345.                             }
    346.                             else
    347.                                 break;
    348.                         }
    349.                     }                  
    350.                    
    351.                 }
    352.                 else
    353.                 {
    354.                     return false;
    355.                 }
    356.                 return true;                   
    357.                 break;
    358.             case "https":
    359.                 if(!$this->curl_path)
    360.                     return false;
    361.                 if(function_exists("is_executable"))
    362.                     if (!is_executable($this->curl_path))
    363.                         return false;
    364.                 $this->host = $URI_PARTS["host"];
    365.                 if(!empty($URI_PARTS["port"]))
    366.                     $this->port = $URI_PARTS["port"];
    367.                 if($this->_isproxy)
    368.                 {
    369.                     // using proxy, send entire URI
    370.                     $this->_httpsrequest($URI, $URI, $this->_submit_method, $this->_submit_type, $postdata);
    371.                 }
    372.                 else
    373.                 {
    374.                     $path = $URI_PARTS["path"].($URI_PARTS["query"] ? "?".$URI_PARTS["query"] : "");
    375.                     // no proxy, send only the path
    376.                     $this->_httpsrequest($path, $URI, $this->_submit_method, $this->_submit_type, $postdata);
    377.                 }
    378.  
    379.                 if($this->_redirectaddr)
    380.                 {
    381.                     /* url was redirected, check if we've hit the max depth */
    382.                     if($this->maxredirs > $this->_redirectdepth)
    383.                     {                      
    384.                         if(!preg_match("|^".$URI_PARTS["scheme"]."://|", $this->_redirectaddr))
    385.                             $this->_redirectaddr = $this->_expandlinks($this->_redirectaddr,$URI_PARTS["scheme"]."://".$URI_PARTS["host"]);                    
    386.  
    387.                         // only follow redirect if it's on this site, or offsiteok is true
    388.                         if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok)
    389.                         {
    390.                             /* follow the redirect */
    391.                             $this->_redirectdepth++;
    392.                             $this->lastredirectaddr=$this->_redirectaddr;
    393.                             if( strpos( $this->_redirectaddr, "?" ) > 0 )
    394.                                 $this->fetch($this->_redirectaddr); // the redirect has changed the request method from post to get
    395.                             else
    396.                                 $this->submit($this->_redirectaddr,$formvars, $formfiles);
    397.                         }
    398.                     }
    399.                 }
    400.  
    401.                 if($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0)
    402.                 {
    403.                     $frameurls = $this->_frameurls;
    404.                     $this->_frameurls = array();
    405.  
    406.                     while(list(,$frameurl) = each($frameurls))
    407.                     {                                                      
    408.                         if($this->_framedepth < $this->maxframes)
    409.                         {
    410.                             $this->fetch($frameurl);
    411.                             $this->_framedepth++;
    412.                         }
    413.                         else
    414.                             break;
    415.                     }
    416.                 }                  
    417.                 return true;                   
    418.                 break;
    419.                
    420.             default:
    421.                 // not a valid protocol
    422.                 $this->error    =   'Invalid protocol "'.$URI_PARTS["scheme"].'"\n';
    423.                 return false;
    424.                 break;
    425.         }      
    426.         return true;
    427.     }
    428.  
    429. /*======================================================================*\
    430.     Function:   fetchlinks
    431.     Purpose:    fetch the links from a web page
    432.     Input:      $URI    where you are fetching from
    433.     Output:     $this->results  an array of the URLs
    434. \*======================================================================*/
    435.  
    436.     function fetchlinks($URI)
    437.     {
    438.         if ($this->fetch($URI))
    439.         {          
    440.             if($this->lastredirectaddr)
    441.                 $URI = $this->lastredirectaddr;
    442.             if(is_array($this->results))
    443.             {
    444.                 for($x=0;$x<count($this->results);$x++)
    445.                     $this->results[$x] = $this->_striplinks($this->results[$x]);
    446.             }
    447.             else
    448.                 $this->results = $this->_striplinks($this->results);
    449.  
    450.             if($this->expandlinks)
    451.                 $this->results = $this->_expandlinks($this->results, $URI);
    452.             return true;
    453.         }
    454.         else
    455.             return false;
    456.     }
    457.  
    458. /*======================================================================*\
    459.     Function:   fetchform
    460.     Purpose:    fetch the form elements from a web page
    461.     Input:      $URI    where you are fetching from
    462.     Output:     $this->results  the resulting html form
    463. \*======================================================================*/
    464.  
    465.     function fetchform($URI)
    466.     {
    467.        
    468.         if ($this->fetch($URI))
    469.         {          
    470.  
    471.             if(is_array($this->results))
    472.             {
    473.                 for($x=0;$x<count($this->results);$x++)
    474.                     $this->results[$x] = $this->_stripform($this->results[$x]);
    475.             }
    476.             else
    477.                 $this->results = $this->_stripform($this->results);
    478.            
    479.             return true;
    480.         }
    481.         else
    482.             return false;
    483.     }
    484.    
    485.    
    486. /*======================================================================*\
    487.     Function:   fetchtext
    488.     Purpose:    fetch the text from a web page, stripping the links
    489.     Input:      $URI    where you are fetching from
    490.     Output:     $this->results  the text from the web page
    491. \*======================================================================*/
    492.  
    493.     function fetchtext($URI)
    494.     {
    495.         if($this->fetch($URI))
    496.         {          
    497.             if(is_array($this->results))
    498.             {
    499.                 for($x=0;$x<count($this->results);$x++)
    500.                     $this->results[$x] = $this->_striptext($this->results[$x]);
    501.             }
    502.             else
    503.                 $this->results = $this->_striptext($this->results);
    504.             return true;
    505.         }
    506.         else
    507.             return false;
    508.     }
    509.  
    510. /*======================================================================*\
    511.     Function:   submitlinks
    512.     Purpose:    grab links from a form submission
    513.     Input:      $URI    where you are submitting from
    514.     Output:     $this->results  an array of the links from the post
    515. \*======================================================================*/
    516.  
    517.     function submitlinks($URI, $formvars="", $formfiles="")
    518.     {
    519.         if($this->submit($URI,$formvars, $formfiles))
    520.         {          
    521.             if($this->lastredirectaddr)
    522.                 $URI = $this->lastredirectaddr;
    523.             if(is_array($this->results))
    524.             {
    525.                 for($x=0;$x<count($this->results);$x++)
    526.                 {
    527.                     $this->results[$x] = $this->_striplinks($this->results[$x]);
    528.                     if($this->expandlinks)
    529.                         $this->results[$x] = $this->_expandlinks($this->results[$x],$URI);
    530.                 }
    531.             }
    532.             else
    533.             {
    534.                 $this->results = $this->_striplinks($this->results);
    535.                 if($this->expandlinks)
    536.                     $this->results = $this->_expandlinks($this->results,$URI);
    537.             }
    538.             return true;
    539.         }
    540.         else
    541.             return false;
    542.     }
    543.  
    544. /*======================================================================*\
    545.     Function:   submittext
    546.     Purpose:    grab text from a form submission
    547.     Input:      $URI    where you are submitting from
    548.     Output:     $this->results  the text from the web page
    549. \*======================================================================*/
    550.  
    551.     function submittext($URI, $formvars = "", $formfiles = "")
    552.     {
    553.         if($this->submit($URI,$formvars, $formfiles))
    554.         {          
    555.             if($this->lastredirectaddr)
    556.                 $URI = $this->lastredirectaddr;
    557.             if(is_array($this->results))
    558.             {
    559.                 for($x=0;$x<count($this->results);$x++)
    560.                 {
    561.                     $this->results[$x] = $this->_striptext($this->results[$x]);
    562.                     if($this->expandlinks)
    563.                         $this->results[$x] = $this->_expandlinks($this->results[$x],$URI);
    564.                 }
    565.             }
    566.             else
    567.             {
    568.                 $this->results = $this->_striptext($this->results);
    569.                 if($this->expandlinks)
    570.                     $this->results = $this->_expandlinks($this->results,$URI);
    571.             }
    572.             return true;
    573.         }
    574.         else
    575.             return false;
    576.     }
    577.  
    578.    
    579.  
    580. /*======================================================================*\
    581.     Function:   set_submit_multipart
    582.     Purpose:    Set the form submission content type to
    583.                 multipart/form-data
    584. \*======================================================================*/
    585.     function set_submit_multipart()
    586.     {
    587.         $this->_submit_type = "multipart/form-data";
    588.     }
    589.  
    590.    
    591. /*======================================================================*\
    592.     Function:   set_submit_normal
    593.     Purpose:    Set the form submission content type to
    594.                 application/x-www-form-urlencoded
    595. \*======================================================================*/
    596.     function set_submit_normal()
    597.     {
    598.         $this->_submit_type = "application/x-www-form-urlencoded";
    599.     }
    600.  
    601.    
    602.    
    603.  
    604. /*======================================================================*\
    605.     Private functions
    606. \*======================================================================*/
    607.    
    608.    
    609. /*======================================================================*\
    610.     Function:   _striplinks
    611.     Purpose:    strip the hyperlinks from an html document
    612.     Input:      $document   document to strip.
    613.     Output:     $match      an array of the links
    614. \*======================================================================*/
    615.  
    616.     function _striplinks($document)
    617.     {  
    618.         preg_match_all("'<\s*a\s.*?href\s*=\s*          # find <a href=
    619.                         ([\"\'])?                   # find single or double quote
    620.                         (?(1) (.*?)\\1 | ([^\s\>]+))        # if quote found, match up to next matching
    621.                                                     # quote, otherwise match up to next space
    622.                         'isx",$document,$links);
    623.                        
    624.  
    625.         // catenate the non-empty matches from the conditional subpattern
    626.  
    627.         while(list($key,$val) = each($links[2]))
    628.         {
    629.             if(!empty($val))
    630.                 $match[] = $val;
    631.         }              
    632.        
    633.         while(list($key,$val) = each($links[3]))
    634.         {
    635.             if(!empty($val))
    636.                 $match[] = $val;
    637.         }      
    638.        
    639.         // return the links
    640.         return $match;
    641.     }
    642.  
    643. /*======================================================================*\
    644.     Function:   _stripform
    645.     Purpose:    strip the form elements from an html document
    646.     Input:      $document   document to strip.
    647.     Output:     $match      an array of the links
    648. \*======================================================================*/
    649.  
    650.     function _stripform($document)
    651.     {  
    652.         preg_match_all("'<\/?(FORM|INPUT|SELECT|TEXTAREA|(OPTION))[^<>]*>(?(2)(.*(?=<\/?(option|select)[^<>]*>[\r\n]*)|(?=[\r\n]*))|(?=[\r\n]*))'Usi",$document,$elements);
    653.        
    654.         // catenate the matches
    655.         $match = implode("\r\n",$elements[0]);
    656.                
    657.         // return the links
    658.         return $match;
    659.     }
    660.  
    661.    
    662.    
    663. /*======================================================================*\
    664.     Function:   _striptext
    665.     Purpose:    strip the text from an html document
    666.     Input:      $document   document to strip.
    667.     Output:     $text       the resulting text
    668. \*======================================================================*/
    669.  
    670.     function _striptext($document)
    671.     {
    672.        
    673.         // I didn't use preg eval (//e) since that is only available in PHP 4.0.
    674.         // so, list your entities one by one here. I included some of the
    675.         // more common ones.
    676.                                
    677.         $search = array("'<script[^>]*?>.*?</script>'si",   // strip out javascript
    678.                         "'<[\/\!]*?[^<>]*?>'si",            // strip out html tags
    679.                         "'([\r\n])[\s]+'",                  // strip out white space
    680.                         "'&(quot|#34|#034|#x22);'i",        // replace html entities
    681.                         "'&(amp|#38|#038|#x26);'i",         // added hexadecimal values
    682.                         "'&(lt|#60|#060|#x3c);'i",
    683.                         "'&(gt|#62|#062|#x3e);'i",
    684.                         "'&(nbsp|#160|#xa0);'i",
    685.                         "'&(iexcl|#161);'i",
    686.                         "'&(cent|#162);'i",
    687.                         "'&(pound|#163);'i",
    688.                         "'&(copy|#169);'i",
    689.                         "'&(reg|#174);'i",
    690.                         "'&(deg|#176);'i",
    691.                         "'&(#39|#039|#x27);'",
    692.                         "'&(euro|#8364);'i",                // europe
    693.                         "'&a(uml|UML);'",                   // german
    694.                         "'&o(uml|UML);'",
    695.                         "'&u(uml|UML);'",
    696.                         "'&A(uml|UML);'",
    697.                         "'&O(uml|UML);'",
    698.                         "'&U(uml|UML);'",
    699.                         "'&szlig;'i",
    700.                         );
    701.         $replace = array(   "",
    702.                             "",
    703.                             "\\1",
    704.                             "\"",
    705.                             "&",
    706.                             "<",
    707.                             ">",
    708.                             " ",
    709.                             chr(161),
    710.                             chr(162),
    711.                             chr(163),
    712.                             chr(169),
    713.                             chr(174),
    714.                             chr(176),
    715.                             chr(39),
    716.                             chr(128),
    717.                             "д",
    718.                             "ц",
    719.                             "ь",
    720.                             "Д",
    721.                             "Ц",
    722.                             "Ь",
    723.                             "Я",
    724.                         );
    725.                    
    726.         $text = preg_replace($search,$replace,$document);
    727.                                
    728.         return $text;
    729.     }
    730.  
    731. /*======================================================================*\
    732.     Function:   _expandlinks
    733.     Purpose:    expand each link into a fully qualified URL
    734.     Input:      $links          the links to qualify
    735.                 $URI            the full URI to get the base from
    736.     Output:     $expandedLinks  the expanded links
    737. \*======================================================================*/
    738.  
    739.     function _expandlinks($links,$URI)
    740.     {
    741.        
    742.         preg_match("/^[^\?]+/",$URI,$match);
    743.  
    744.         $match = preg_replace("|/[^\/\.]+\.[^\/\.]+$|","",$match[0]);
    745.         $match = preg_replace("|/$|","",$match);
    746.         $match_part = parse_url($match);
    747.         $match_root =
    748.         $match_part["scheme"]."://".$match_part["host"];
    749.                
    750.         $search = array(    "|^http://".preg_quote($this->host)."|i",
    751.                             "|^(\/)|i",
    752.                             "|^(?!http://)(?!mailto:)|i",
    753.                             "|/\./|",
    754.                             "|/[^\/]+/\.\./|"
    755.                         );
    756.                        
    757.         $replace = array(   "",
    758.                             $match_root."/",
    759.                             $match."/",
    760.                             "/",
    761.                             "/"
    762.                         );         
    763.                
    764.         $expandedLinks = preg_replace($search,$replace,$links);
    765.  
    766.         return $expandedLinks;
    767.     }
    768.  
    769. /*======================================================================*\
    770.     Function:   _httprequest
    771.     Purpose:    go get the http data from the server
    772.     Input:      $url        the url to fetch
    773.                 $fp         the current open file pointer
    774.                 $URI        the full URI
    775.                 $body       body contents to send if any (POST)
    776.     Output:    
    777. \*======================================================================*/
    778.    
    779.     function _httprequest($url,$fp,$URI,$http_method,$content_type="",$body="")
    780.     {
    781.         $cookie_headers = '';
    782.         if($this->passcookies && $this->_redirectaddr)
    783.             $this->setcookies();
    784.            
    785.         $URI_PARTS = parse_url($URI);
    786.         if(empty($url))
    787.             $url = "/";
    788.         $headers = $http_method." ".$url." ".$this->_httpversion."\r\n";       
    789.         if(!empty($this->agent))
    790.             $headers .= "User-Agent: ".$this->agent."\r\n";
    791.         if(!empty($this->host) && !isset($this->rawheaders['Host'])) {
    792.             $headers .= "Host: ".$this->host;
    793.             if(!empty($this->port))
    794.                 $headers .= ":".$this->port;
    795.             $headers .= "\r\n";
    796.         }
    797.         if(!empty($this->accept))
    798.             $headers .= "Accept: ".$this->accept."\r\n";
    799.         if(!empty($this->referer))
    800.             $headers .= "Referer: ".$this->referer."\r\n";
    801.         if(!empty($this->cookies))
    802.         {          
    803.             if(!is_array($this->cookies))
    804.                 $this->cookies = (array)$this->cookies;
    805.    
    806.             reset($this->cookies);
    807.             if ( count($this->cookies) > 0 ) {
    808.                 $cookie_headers .= 'Cookie: ';
    809.                 foreach ( $this->cookies as $cookieKey => $cookieVal ) {
    810.                 $cookie_headers .= $cookieKey."=".urlencode($cookieVal)."; ";
    811.                 }
    812.                 $headers .= substr($cookie_headers,0,-2) . "\r\n";
    813.             }
    814.         }
    815.         if(!empty($this->rawheaders))
    816.         {
    817.             if(!is_array($this->rawheaders))
    818.                 $this->rawheaders = (array)$this->rawheaders;
    819.             while(list($headerKey,$headerVal) = each($this->rawheaders))
    820.                 $headers .= $headerKey.": ".$headerVal."\r\n";
    821.         }
    822.         if(!empty($content_type)) {
    823.             $headers .= "Content-type: $content_type";
    824.             if ($content_type == "multipart/form-data")
    825.                 $headers .= "; boundary=".$this->_mime_boundary;
    826.             $headers .= "\r\n";
    827.         }
    828.         if(!empty($body))  
    829.             $headers .= "Content-length: ".strlen($body)."\r\n";
    830.         if(!empty($this->user) || !empty($this->pass)) 
    831.             $headers .= "Authorization: Basic ".base64_encode($this->user.":".$this->pass)."\r\n";
    832.        
    833.         //add proxy auth headers
    834.         if(!empty($this->proxy_user))  
    835.             $headers .= 'Proxy-Authorization: ' . 'Basic ' . base64_encode($this->proxy_user . ':' . $this->proxy_pass)."\r\n";
    836.  
    837.  
    838.         $headers .= "\r\n";
    839.        
    840.         // set the read timeout if needed
    841.         if ($this->read_timeout > 0)
    842.             socket_set_timeout($fp, $this->read_timeout);
    843.         $this->timed_out = false;
    844.        
    845.         fwrite($fp,$headers.$body,strlen($headers.$body));
    846.        
    847.         $this->_redirectaddr = false;
    848.         unset($this->headers);
    849.                        
    850.         while($currentHeader = fgets($fp,$this->_maxlinelen))
    851.         {
    852.             if ($this->read_timeout > 0 && $this->_check_timeout($fp))
    853.             {
    854.                 $this->status=-100;
    855.                 return false;
    856.             }
    857.                
    858.             if($currentHeader == "\r\n")
    859.                 break;
    860.                        
    861.             // if a header begins with Location: or URI:, set the redirect
    862.             if(preg_match("/^(Location:|URI:)/i",$currentHeader))
    863.             {
    864.                 // get URL portion of the redirect
    865.                 preg_match("/^(Location:|URI:)[ ]+(.*)/i",chop($currentHeader),$matches);
    866.                 // look for :// in the Location header to see if hostname is included
    867.                 if(!preg_match("|\:\/\/|",$matches[2]))
    868.                 {
    869.                     // no host in the path, so prepend
    870.                     $this->_redirectaddr = $URI_PARTS["scheme"]."://".$this->host.":".$this->port;
    871.                     // eliminate double slash
    872.                     if(!preg_match("|^/|",$matches[2]))
    873.                             $this->_redirectaddr .= "/".$matches[2];
    874.                     else
    875.                             $this->_redirectaddr .= $matches[2];
    876.                 }
    877.                 else
    878.                     $this->_redirectaddr = $matches[2];
    879.             }
    880.        
    881.             if(preg_match("|^HTTP/|",$currentHeader))
    882.             {
    883.                 if(preg_match("|^HTTP/[^\s]*\s(.*?)\s|",$currentHeader, $status))
    884.                 {
    885.                     $this->status= $status[1];
    886.                 }              
    887.                 $this->response_code = $currentHeader;
    888.             }
    889.                
    890.             $this->headers[] = $currentHeader;
    891.         }
    892.  
    893.         $results = '';
    894.         do {
    895.             $_data = fread($fp, $this->maxlength);
    896.             if (strlen($_data) == 0) {
    897.                 break;
    898.             }
    899.             $results .= $_data;
    900.         } while(true);
    901.  
    902.         if ($this->read_timeout > 0 && $this->_check_timeout($fp))
    903.         {
    904.             $this->status=-100;
    905.             return false;
    906.         }
    907.        
    908.         // check if there is a a redirect meta tag
    909.        
    910.         if(preg_match("'<meta[\s]*http-equiv[^>]*?content[\s]*=[\s]*[\"\']?\d+;[\s]*URL[\s]*=[\s]*([^\"\']*?)[\"\']?>'i",$results,$match))
    911.  
    912.         {
    913.             $this->_redirectaddr = $this->_expandlinks($match[1],$URI);
    914.         }
    915.  
    916.         // have we hit our frame depth and is there frame src to fetch?
    917.         if(($this->_framedepth < $this->maxframes) && preg_match_all("'<frame\s+.*src[\s]*=[\'\"]?([^\'\"\>]+)'i",$results,$match))
    918.         {
    919.             $this->results[] = $results;
    920.             for($x=0; $x<count($match[1]); $x++)
    921.                 $this->_frameurls[] = $this->_expandlinks($match[1][$x],$URI_PARTS["scheme"]."://".$this->host);
    922.         }
    923.         // have we already fetched framed content?
    924.         elseif(is_array($this->results))
    925.             $this->results[] = $results;
    926.         // no framed content
    927.         else
    928.             $this->results = $results;
    929.        
    930.         return true;
    931.     }
    932.  
    933. /*======================================================================*\
    934.     Function:   _httpsrequest
    935.     Purpose:    go get the https data from the server using curl
    936.     Input:      $url        the url to fetch
    937.                 $URI        the full URI
    938.                 $body       body contents to send if any (POST)
    939.     Output:    
    940. \*======================================================================*/
    941.    
    942.     function _httpsrequest($url,$URI,$http_method,$content_type="",$body="")
    943.     {  
    944.         if($this->passcookies && $this->_redirectaddr)
    945.             $this->setcookies();
    946.  
    947.         $headers = array();    
    948.                    
    949.         $URI_PARTS = parse_url($URI);
    950.         if(empty($url))
    951.             $url = "/";
    952.         // GET ... header not needed for curl
    953.         //$headers[] = $http_method." ".$url." ".$this->_httpversion;      
    954.         if(!empty($this->agent))
    955.             $headers[] = "User-Agent: ".$this->agent;
    956.         if(!empty($this->host))
    957.             if(!empty($this->port))
    958.                 $headers[] = "Host: ".$this->host.":".$this->port;
    959.             else
    960.                 $headers[] = "Host: ".$this->host;
    961.         if(!empty($this->accept))
    962.             $headers[] = "Accept: ".$this->accept;
    963.         if(!empty($this->referer))
    964.             $headers[] = "Referer: ".$this->referer;
    965.         if(!empty($this->cookies))
    966.         {          
    967.             if(!is_array($this->cookies))
    968.                 $this->cookies = (array)$this->cookies;
    969.    
    970.             reset($this->cookies);
    971.             if ( count($this->cookies) > 0 ) {
    972.                 $cookie_str = 'Cookie: ';
    973.                 foreach ( $this->cookies as $cookieKey => $cookieVal ) {
    974.                 $cookie_str .= $cookieKey."=".urlencode($cookieVal)."; ";
    975.                 }
    976.                 $headers[] = substr($cookie_str,0,-2);
    977.             }
    978.         }
    979.         if(!empty($this->rawheaders))
    980.         {
    981.             if(!is_array($this->rawheaders))
    982.                 $this->rawheaders = (array)$this->rawheaders;
    983.             while(list($headerKey,$headerVal) = each($this->rawheaders))
    984.                 $headers[] = $headerKey.": ".$headerVal;
    985.         }
    986.         if(!empty($content_type)) {
    987.             if ($content_type == "multipart/form-data")
    988.                 $headers[] = "Content-type: $content_type; boundary=".$this->_mime_boundary;
    989.             else
    990.                 $headers[] = "Content-type: $content_type";
    991.         }
    992.         if(!empty($body))  
    993.             $headers[] = "Content-length: ".strlen($body);
    994.         if(!empty($this->user) || !empty($this->pass)) 
    995.             $headers[] = "Authorization: BASIC ".base64_encode($this->user.":".$this->pass);
    996.            
    997.         for($curr_header = 0; $curr_header < count($headers); $curr_header++) {
    998.             $safer_header = strtr( $headers[$curr_header], "\"", " " );
    999.             $cmdline_params .= " -H \"".$safer_header."\"";
    1000.         }
    1001.        
    1002.         if(!empty($body))
    1003.             $cmdline_params .= " -d \"$body\"";
    1004.        
    1005.         if($this->read_timeout > 0)
    1006.             $cmdline_params .= " -m ".$this->read_timeout;
    1007.        
    1008.         $headerfile = tempnam($temp_dir, "sno");
    1009.  
    1010.         exec($this->curl_path." -k -D \"$headerfile\"".$cmdline_params." \"".escapeshellcmd($URI)."\"",$results,$return);
    1011.        
    1012.         if($return)
    1013.         {
    1014.             $this->error = "Error: cURL could not retrieve the document, error $return.";
    1015.             return false;
    1016.         }
    1017.            
    1018.            
    1019.         $results = implode("\r\n",$results);
    1020.        
    1021.         $result_headers = file("$headerfile");
    1022.                        
    1023.         $this->_redirectaddr = false;
    1024.         unset($this->headers);
    1025.                        
    1026.         for($currentHeader = 0; $currentHeader < count($result_headers); $currentHeader++)
    1027.         {
    1028.            
    1029.             // if a header begins with Location: or URI:, set the redirect
    1030.             if(preg_match("/^(Location: |URI: )/i",$result_headers[$currentHeader]))
    1031.             {
    1032.                 // get URL portion of the redirect
    1033.                 preg_match("/^(Location: |URI:)\s+(.*)/",chop($result_headers[$currentHeader]),$matches);
    1034.                 // look for :// in the Location header to see if hostname is included
    1035.                 if(!preg_match("|\:\/\/|",$matches[2]))
    1036.                 {
    1037.                     // no host in the path, so prepend
    1038.                     $this->_redirectaddr = $URI_PARTS["scheme"]."://".$this->host.":".$this->port;
    1039.                     // eliminate double slash
    1040.                     if(!preg_match("|^/|",$matches[2]))
    1041.                             $this->_redirectaddr .= "/".$matches[2];
    1042.                     else
    1043.                             $this->_redirectaddr .= $matches[2];
    1044.                 }
    1045.                 else
    1046.                     $this->_redirectaddr = $matches[2];
    1047.             }
    1048.        
    1049.             if(preg_match("|^HTTP/|",$result_headers[$currentHeader]))
    1050.                 $this->response_code = $result_headers[$currentHeader];
    1051.  
    1052.             $this->headers[] = $result_headers[$currentHeader];
    1053.         }
    1054.  
    1055.         // check if there is a a redirect meta tag
    1056.        
    1057.         if(preg_match("'<meta[\s]*http-equiv[^>]*?content[\s]*=[\s]*[\"\']?\d+;[\s]*URL[\s]*=[\s]*([^\"\']*?)[\"\']?>'i",$results,$match))
    1058.         {
    1059.             $this->_redirectaddr = $this->_expandlinks($match[1],$URI);
    1060.         }
    1061.  
    1062.         // have we hit our frame depth and is there frame src to fetch?
    1063.         if(($this->_framedepth < $this->maxframes) && preg_match_all("'<frame\s+.*src[\s]*=[\'\"]?([^\'\"\>]+)'i",$results,$match))
    1064.         {
    1065.             $this->results[] = $results;
    1066.             for($x=0; $x<count($match[1]); $x++)
    1067.                 $this->_frameurls[] = $this->_expandlinks($match[1][$x],$URI_PARTS["scheme"]."://".$this->host);
    1068.         }
    1069.         // have we already fetched framed content?
    1070.         elseif(is_array($this->results))
    1071.             $this->results[] = $results;
    1072.         // no framed content
    1073.         else
    1074.             $this->results = $results;
    1075.  
    1076.         unlink("$headerfile");
    1077.        
    1078.         return true;
    1079.     }
    1080.  
    1081. /*======================================================================*\
    1082.     Function:   setcookies()
    1083.     Purpose:    set cookies for a redirection
    1084. \*======================================================================*/
    1085.    
    1086.     function setcookies()
    1087.     {
    1088.         for($x=0; $x<count($this->headers); $x++)
    1089.         {
    1090.         if(preg_match('/^set-cookie:[\s]+([^=]+)=([^;]+)/i', $this->headers[$x],$match))
    1091.             $this->cookies[$match[1]] = urldecode($match[2]);
    1092.         }
    1093.     }
    1094.  
    1095.    
    1096. /*======================================================================*\
    1097.     Function:   _check_timeout
    1098.     Purpose:    checks whether timeout has occurred
    1099.     Input:      $fp file pointer
    1100. \*======================================================================*/
    1101.  
    1102.     function _check_timeout($fp)
    1103.     {
    1104.         if ($this->read_timeout > 0) {
    1105.             $fp_status = socket_get_status($fp);
    1106.             if ($fp_status["timed_out"]) {
    1107.                 $this->timed_out = true;
    1108.                 return true;
    1109.             }
    1110.         }
    1111.         return false;
    1112.     }
    1113.  
    1114. /*======================================================================*\
    1115.     Function:   _connect
    1116.     Purpose:    make a socket connection
    1117.     Input:      $fp file pointer
    1118. \*======================================================================*/
    1119.    
    1120.     function _connect(&$fp)
    1121.     {
    1122.         if(!empty($this->proxy_host) && !empty($this->proxy_port))
    1123.             {
    1124.                 $this->_isproxy = true;
    1125.                
    1126.                 $host = $this->proxy_host;
    1127.                 $port = $this->proxy_port;
    1128.             }
    1129.         else
    1130.         {
    1131.             $host = $this->host;
    1132.             $port = $this->port;
    1133.         }
    1134.    
    1135.         $this->status = 0;
    1136.        
    1137.         if($fp = fsockopen(
    1138.                     $host,
    1139.                     $port,
    1140.                     $errno,
    1141.                     $errstr,
    1142.                     $this->_fp_timeout
    1143.                     ))
    1144.         {
    1145.             // socket connection succeeded
    1146.  
    1147.             return true;
    1148.         }
    1149.         else
    1150.         {
    1151.             // socket connection failed
    1152.             $this->status = $errno;
    1153.             switch($errno)
    1154.             {
    1155.                 case -3:
    1156.                     $this->error="socket creation failed (-3)";
    1157.                 case -4:
    1158.                     $this->error="dns lookup failure (-4)";
    1159.                 case -5:
    1160.                     $this->error="connection refused or timed out (-5)";
    1161.                 default:
    1162.                     $this->error="connection failed (".$errno.")";
    1163.             }
    1164.             return false;
    1165.         }
    1166.     }
    1167. /*======================================================================*\
    1168.     Function:   _disconnect
    1169.     Purpose:    disconnect a socket connection
    1170.     Input:      $fp file pointer
    1171. \*======================================================================*/
    1172.    
    1173.     function _disconnect($fp)
    1174.     {
    1175.         return(fclose($fp));
    1176.     }
    1177.  
    1178.    
    1179. /*======================================================================*\
    1180.     Function:   _prepare_post_body
    1181.     Purpose:    Prepare post body according to encoding type
    1182.     Input:      $formvars  - form variables
    1183.                 $formfiles - form upload files
    1184.     Output:     post body
    1185. \*======================================================================*/
    1186.    
    1187.     function _prepare_post_body($formvars, $formfiles)
    1188.     {
    1189.         settype($formvars, "array");
    1190.         settype($formfiles, "array");
    1191.         $postdata = '';
    1192.  
    1193.         if (count($formvars) == 0 && count($formfiles) == 0)
    1194.             return;
    1195.        
    1196.         switch ($this->_submit_type) {
    1197.             case "application/x-www-form-urlencoded":
    1198.                 reset($formvars);
    1199.                 while(list($key,$val) = each($formvars)) {
    1200.                     if (is_array($val) || is_object($val)) {
    1201.                         while (list($cur_key, $cur_val) = each($val)) {
    1202.                             $postdata .= urlencode($key)."[]=".urlencode($cur_val)."&";
    1203.                         }
    1204.                     } else
    1205.                         $postdata .= urlencode($key)."=".urlencode($val)."&";
    1206.                 }
    1207.                 break;
    1208.  
    1209.             case "multipart/form-data":
    1210.                 $this->_mime_boundary = "Snoopy".md5(uniqid(microtime()));
    1211.                
    1212.                 reset($formvars);
    1213.                 while(list($key,$val) = each($formvars)) {
    1214.                     if (is_array($val) || is_object($val)) {
    1215.                         while (list($cur_key, $cur_val) = each($val)) {
    1216.                             $postdata .= "--".$this->_mime_boundary."\r\n";
    1217.                             $postdata .= "Content-Disposition: form-data; name=\"$key\[\]\"\r\n\r\n";
    1218.                             $postdata .= "$cur_val\r\n";
    1219.                         }
    1220.                     } else {
    1221.                         $postdata .= "--".$this->_mime_boundary."\r\n";
    1222.                         $postdata .= "Content-Disposition: form-data; name=\"$key\"\r\n\r\n";
    1223.                         $postdata .= "$val\r\n";
    1224.                     }
    1225.                 }
    1226.                
    1227.                 reset($formfiles);
    1228.                 while (list($field_name, $file_names) = each($formfiles)) {
    1229.                     settype($file_names, "array");
    1230.                     while (list(, $file_name) = each($file_names)) {
    1231.                         if (!is_readable($file_name)) continue;
    1232.  
    1233.                         $fp = fopen($file_name, "r");
    1234.                         $file_content = fread($fp, filesize($file_name));
    1235.                         fclose($fp);
    1236.                         $base_name = basename($file_name);
    1237.  
    1238.                         $postdata .= "--".$this->_mime_boundary."\r\n";
    1239.                         $postdata .= "Content-Disposition: form-data; name=\"$field_name\"; filename=\"$base_name\"\r\n\r\n";
    1240.                         $postdata .= "$file_content\r\n";
    1241.                     }
    1242.                 }
    1243.                 $postdata .= "--".$this->_mime_boundary."--\r\n";
    1244.                 break;
    1245.         }
    1246.  
    1247.         return $postdata;
    1248.     }
    1249. }
    1250.  
    1251. ?>
    Добавлено спустя 2 минуты 8 секунд:
    В этой штуке если найдешь почему по разному голосуют снупи и браузер-спрашивай про много акков и прокси.
    Прокси наверно можно не использовать ,вроде как с акка и 1 айпи раз 10 можно голосовать
     
  10. georgela

    georgela Активный пользователь

    С нами с:
    11 май 2011
    Сообщения:
    395
    Симпатии:
    0
    Думаю Теле2 продолжит голосилку если не на свитер,то может и на айпад,ноут,комп...Включайте мозг ребята!
     
  11. igordata

    igordata Суперстар
    Команда форума Модератор

    С нами с:
    18 мар 2010
    Сообщения:
    32.408
    Симпатии:
    1.768
    я думал, ты просто играешься. а ты реально планируешь зохватить свитер или iPad? =)

    Добавлено спустя 26 минут 24 секунды:
    http://habrahabr.ru/post/165999/
     
  12. georgela

    georgela Активный пользователь

    С нами с:
    11 май 2011
    Сообщения:
    395
    Симпатии:
    0
    [​IMG]
    1)Это ж конкурс по накрутке
    2)Веб сервер должен адекватно реагировать на имитацию снупи
    3)Надоел дом 2 который в пхп полез
     
  13. georgela

    georgela Активный пользователь

    С нами с:
    11 май 2011
    Сообщения:
    395
    Симпатии:
    0