|
| 1 | +class WebBrowser { |
| 2 | + public $user_agent = ''; |
| 3 | + public $cookie = ''; |
| 4 | + public $protocol = ''; |
| 5 | + public $domain = ''; |
| 6 | + public $desthost = ''; |
| 7 | + public $username = ''; |
| 8 | + public $password = ''; |
| 9 | + public $port = ''; |
| 10 | + public $uri = ''; |
| 11 | + public $query_string = ''; |
| 12 | + public $anchor = ''; |
| 13 | + public $rerferer = ''; |
| 14 | + public $method = ''; |
| 15 | + |
| 16 | + public function __contruct() { |
| 17 | + $this->user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:26.0) Gecko/20100101 Firefox/26.0'; |
| 18 | + $this->cookie = ''; |
| 19 | + $this->setURL('http://www.google.com'); |
| 20 | + } |
| 21 | + |
| 22 | + public function setURL(url) { |
| 23 | + // parsing URL to protocol, host, username, password, port, URI, query string |
| 24 | + $regexUrl = "((https?|ftp)\:\/\/)?"; // SCHEME |
| 25 | + $regexUrl .= "([a-zA-Z0-9+!*(),;?&=\$_.-]+(\:[a-zA-Z0-9+!*(),;?&=\$_.-]+)?@)?"; // User and Pass |
| 26 | + $regexUrl .= "([a-zA-Z0-9-]+)\.([a-zA-Z]{2,3})"; // Host or IP |
| 27 | + $regexUrl .= "(\:[0-9]{2,5})?"; // Port |
| 28 | + $regexUrl .= "(\/([a-zA-Z0-9+\$_-]\.?)+)*\/?"; // Path |
| 29 | + $regexUrl .= "(\?[a-zA-Z+&\$_.-][a-zA-Z0-9;:@&%=+\/\$_.-]*)?"; // GET Query |
| 30 | + $regexUrl .= "(#[a-zA-Z_.-][a-zA-Z0-9+\$_.-]*)?"; // Anchor |
| 31 | + if(preg_match_all("/$regexUrl/", $url, $matches, PREG_PATTERN_ORDER)) |
| 32 | + { |
| 33 | + try |
| 34 | + { |
| 35 | + foreach($matches[0] as $urlToTrim1) |
| 36 | + { |
| 37 | + $url= $urlToTrim1; |
| 38 | + echo $url; |
| 39 | + } |
| 40 | + } |
| 41 | + catch(Exception $e) |
| 42 | + { |
| 43 | + $url="-1"; |
| 44 | + } |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | +// public function resolveDomain() { |
| 49 | +// if ($this->domain != '') { |
| 50 | +// $temp_array = gethostbynamel($this->domain); |
| 51 | +// if ($temp_array) $this->desthost = $temp_array[0]; |
| 52 | +// } |
| 53 | +// } |
| 54 | + |
| 55 | + public function getWebPage() { |
| 56 | + $fh = fsockopen($this->domain, 80, $errno, $errstr, 30); |
| 57 | + if (!fh) { |
| 58 | + echo "$errstr ($errno)<br />\n"; |
| 59 | + } else { |
| 60 | + $buf = "GET $this->uri HTTP/1.1\r\n"; |
| 61 | + $buf .= "Host: $this->domain\r\n"; |
| 62 | + $buf .= "User-Agent: $this->user_agent\r\n"; |
| 63 | + if ($this->cookie != '') $buf .= "Cookie: $this->cookie\r\n"; |
| 64 | + if ($this->referer != '') $buf .= "Referer: $this->referer\r\n"; |
| 65 | + |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + public function postData() { |
| 70 | + $fh = fsockopen($this->domain, 80, $errno, $errstr, 30); |
| 71 | + if (!fh) { |
| 72 | + echo "$errstr ($errno)<br />\n"; |
| 73 | + } else { |
| 74 | + $buf = "POST $this->uri HTTP/1.1\r\n"; |
| 75 | + $buf .= "Host: $this->domain\r\n"; |
| 76 | + $buf .= "User-Agent: $this->user_agent\r\n"; |
| 77 | + if ($this->cookie != '') $buf .= "Cookie: $this->cookie\r\n"; |
| 78 | + if ($this->referer != '') $buf .= "Referer: $this->referer\r\n"; |
| 79 | + |
| 80 | + } |
| 81 | + } |
| 82 | +} |
0 commit comments