Вход Регистрация
* Pelmeshka

Функция получения страницы через сокеты

  1. <?php
  2. function get_page($site,$page,$isheaders=false,$ua='Opera 9.27 (compatible; MSIE 6.0; Windows NT 5.1; ru)',$ref='',$cookie='',$post='')
  3. {
  4. $page=trim($page);
  5. $site=trim($site);
  6. $socket = fsockopen($site, 80, $errno, $errstr, 15);
  7. if ($socket){
  8.  
  9. if ($post!=''){
  10. $send = "POST $page HTTP/1.0
  11. ";
  12. $send .= "Content-Length: ". strlen($post) ."
  13. ";
  14. $send .= "Content-Type: application/x-www-form-urlencoded; charset=utf-8
  15. ";
  16. } else $send = "GET $page HTTP/1.0
  17. ";
  18. $send .= "User-Agent: $ua
  19. ";
  20. $send .= "Host: $site
  21. ";
  22. $send .= "Accept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1
  23. ";
  24. if($ref!='') $send .= "Referer: $ref
  25. ";
  26. if($cookie!=''){
  27. $send .= "Cookie: $cookie
  28. ";
  29. $send .= 'Cookie2: $Version=1'."
  30. ";
  31. }
  32. $send .= "Accept-Language: ru,en;q=0.9,ru-RU;q=0.8
  33. ";
  34. $send .= "Connection: close
  35.  
  36. ".$post;
  37.  
  38.  
  39. if(fputs($socket,$send)) {
  40. if(!$isheaders) while(fgets($socket,1024)!="
  41. " && !feof($socket));
  42. $he="";
  43. while(!feof($socket)) $he.=fread($socket,10240);
  44. };
  45. fclose($socket);
  46. }
  47. return $he;
  48. };
  49. ?>
» Описание: Функция получения страницы через сокеты
» Время добавления: 7 Ноября 2014 в 18:14
» Посмотров: 1784
» textarea
» Рейтинг: [+0 | -0]
Комментарии [0]
Онлайн: 1
Реклама