티스토리 뷰

http://tetris.tistory.com/328

 

  1. function get_web_data($url) 
  2. $info = parse_url($url); 
  3. $send = "POST " . $info["path"] . " HTTP/1.1\r\n"
  4.         . "Host: " . $info["host"] . "\r\n"
  5.         . "Content-type: application/x-www-form-urlencoded\r\n"
  6.         . "Connection: close\r\n\r\n" ; 
  7. $fp = fsockopen($info["host"], 80); 
  8. fputs($fp, $send); 
  9. $start = false; 
  10. $raw_data = null; 
  11. while (!feof ($fp))  
  12.     { 
  13. $tmp = fgets($fp, 1024); 
  14. if ($start == true) $raw_data .= $tmp; 
  15. if ($tmp == "\r\n") $start = true; 
  16.     } 
  17.     fclose($fp); 
  18. return $raw_data; 
  19. function get_web_header($url) 
  20. $info = parse_url($url); 
  21. $send = "GET " . $info["path"] . " HTTP/1.1\r\n"; 
  22. $send .= "Host: ".$info["host"]."\r\n"; 
  23. $send .= "Connection: Close\r\n\r\n"; 
  24. $fp = fsockopen($info["host"], 80); 
  25. fputs($fp, $send); 
  26. $start = false; 
  27. $header = array(); 
  28. $count = 0; 
  29. while (!feof ($fp))  
  30.     { 
  31. $tmp = fgets($fp, 128); 
  32. if ($start == true) break; 
  33. else
  34.         { 
  35. if ($tmp != "\r\n") 
  36.             { 
  37. $header[$count] = $tmp; 
  38. $count++; 
  39.             } 
  40.         } 
  41. if ($tmp == "\r\n") $start = true; 
  42.     } 
  43.     fclose($fp); 
  44. return $header; 

 

 

--------------------

 

 

  1. function is_exist_remote_file($url) 
  2. if (emptyempty($url) == true) return false; 
  3. $value = $this->get_web_header($url); 
  4. $pos = strpos($value[0], "200 OK"); 
  5. if ($pos > 0) return true; 
  6. return false; 
공지사항