| <?php |
| |
| define("URL_OK","http/1.1 200 ok"); |
| |
| class URLCheck { |
| var $_fp; |
| var $_url; |
| var $_host; |
| var $_uri; |
| var $_port; |
| |
| function _scan_url(){ |
| $req = $this->_url; |
| |
| $pos = strpos($req, '://'); |
| $req = substr($req, $pos+3); |
| $pos = strpos($req, '/'); |
| if ($pos === false) |
| $pos = strlen($req); |
| $host = substr($req, 0, $pos); |
| $this->_host = $host; |
| $this->_port = 80; |
| $this->_uri = substr($req, $pos); |
| if ($this->_uri == '') |
| $this->_uri = '/'; |
| } |
| |
| function URLCheck($url){ |
| $this->_url = $url; |
| $this->_scan_url(); |
| } |
| |
| function urlExists(){ |
| $req = "GET ".$this->_uri." HTTP/1.0\r\n"."Host: ".$this->_host."\r\n\r\n"; |
| $this->_fp = fsockopen($this->_host, $this->_port); |
| fwrite($this->_fp, $req); |
| while(is_resource($this->_fp) && $this->_fp && !feof($this->_fp)){ |
| $response = fread($this->_fp, 1024); |
| if (stristr($response,URL_OK)){ |
| fclose($this->_fp); |
| return 1; |
| } |
| } |
| fclose($this->_fp); |
| return 0; |
| } |
| } |
| ?> |