За последние 24 часа нас посетили 204554 программиста и 2113 роботов. Сейчас ищут 2055 программистов ...

Как создать подобие анонимайзера?

Тема в разделе "PHP для новичков", создана пользователем Roomlife, 26 янв 2011.

  1. Roomlife

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

    С нами с:
    6 авг 2010
    Сообщения:
    34
    Симпатии:
    0
    Что имеется: авторизация на конкретном сайте через curl, отображение необходимой страницы. На странице имеются ссылки вида <a href=?useaction=
    Что нужно: вставить в ссылку начало, чтобы получилось вроде этого: mail.ru?useaction=
    отображение результатов запроса в том же окне. т.е. получается нечто фрейвомое.
    код примерно следующий:

    Код (Text):
    1.  
    2. <?PHP
    3.  
    4. $script_url = trim($_GET['url']);
    5.  
    6. $url_domain = 'http://www.yandex.ru.ru/';
    7.  
    8. class cURL {
    9. var $headers;
    10. var $user_agent;
    11. var $compression;
    12. var $cookie_file;
    13. var $proxy;
    14.  
    15.  
    16. function cURL($cookies=TRUE,$cookie='cookies.txt',$compression='gzip',$proxy='') {
    17.  
    18. $this->headers[] = 'Accept: image/gif, image/x-bitmap, image/jpeg, image/pjpeg';
    19.  
    20. $this->headers[] = 'Connection: Keep-Alive';
    21.  
    22. $this->headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8';
    23.  
    24. $this->user_agent = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0)';
    25.  
    26. $this->compression=$compression;
    27.  
    28. $this->proxy=$proxy;
    29.  
    30. $this->cookies=$cookies;
    31.  
    32. if ($this->cookies == TRUE) $this->cookie($cookie);
    33.  
    34. }
    35.  
    36. function cookie($cookie_file) {
    37.  
    38. if (file_exists($cookie_file)) {
    39.  
    40. $this->cookie_file=$cookie_file;
    41.  
    42. } else {
    43.  
    44. fopen($cookie_file,'w') or $this->error('Кукисы не могут быть открыты.Убедитесь в правах доступа');
    45.  
    46. $this->cookie_file=$cookie_file;
    47.  
    48. fclose($this->$cookie_file);
    49.  
    50. }
    51.  
    52. }
    53.  
    54.  
    55.  
    56. function get($url) {
    57.  
    58. $process = curl_init($url);
    59.  
    60. curl_setopt($process, CURLOPT_HTTPHEADER, $this->headers);
    61.  
    62. curl_setopt($process, CURLOPT_HEADER, 0);
    63.  
    64. curl_setopt($process, CURLOPT_USERAGENT, $this->user_agent);
    65.  
    66. if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEFILE, $this->cookie_file);
    67.  
    68. if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEJAR, $this->cookie_file);
    69.  
    70. curl_setopt($process,CURLOPT_ENCODING , $this->compression);
    71.  
    72. curl_setopt($process, CURLOPT_TIMEOUT, 30);
    73.  
    74. if ($this->proxy) curl_setopt($process, CURLOPT_PROXY, $this->proxy);
    75.  
    76. curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
    77.  
    78. $return = curl_exec($process);
    79.  
    80. curl_close($process);
    81.  
    82. return $return;
    83.  
    84. }
    85.  
    86.  
    87.  
    88.  
    89. function post($url,$data) {
    90.  
    91. $process = curl_init($url);
    92.  
    93. curl_setopt($process, CURLOPT_HTTPHEADER, $this->headers);
    94.  
    95. curl_setopt($process, CURLOPT_HEADER, 1);
    96.  
    97. curl_setopt($process, CURLOPT_USERAGENT, $this->user_agent);
    98.  
    99. if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEFILE, $this->cookie_file);
    100.  
    101. if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEJAR, $this->cookie_file);
    102.  
    103. curl_setopt($process, CURLOPT_ENCODING , $this->compression);
    104.  
    105. curl_setopt($process, CURLOPT_TIMEOUT, 30);
    106.  
    107. if ($this->proxy) curl_setopt($process, CURLOPT_PROXY, $this->proxy);
    108.  
    109. curl_setopt($process, CURLOPT_POSTFIELDS, $data);
    110.  
    111. curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
    112.  
    113. curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
    114.  
    115. curl_setopt($process, CURLOPT_POST, 1);
    116.  
    117. $return = curl_exec($process);
    118.  
    119. curl_close($process);
    120.  
    121. return $return;
    122.  
    123. }
    124.  
    125. function error($error) {
    126.  
    127. echo "<center><div style='width:500px;border: 3px solid #FFEEFF; padding: 3px; background-color: #FFDDFF;font-family: verdana; font-size: 10px'><b>cURL Error</b><br>$error</div></center>";
    128.  
    129. die;
    130.  
    131. }
    132.  
    133. }
    134.  
    135. $cc = new cURL();
    136.  
    137. $page = $cc->post('yandex.ru/yandsearch?cl4url=www');
    138.  
    139.  
    140. function get_cid ($post_page) {
    141.  
    142. if(preg_match_all('/content="0;URL=(.*?)\\"/s', $post_page, $result_html)){
    143.  
    144.         foreach($result_html[0] as $element){    
    145.  
    146.             $element = preg_replace("/\"/","",$element);
    147.  
    148.             $element = strstr( $element,"sid");
    149.  
    150. }}
    151.  
    152. return $element;
    153.  
    154. }
    155.  
    156. $sid = get_cid ($page);
    157.  
    158. $post = $cc->post("http://www.yandex.ru") or die('Error!!!');
    159.  
    160. if ($post) {echo "$post";}
    161.  
    162. ?>
    при отображении кода, будет открыт яндекс. Как сделать, чтобы при запросе на кнопку "поиск", результат отображался в том же окне, а не открывалась вся страница яндекса?