Created
May 13, 2011 16:19
-
-
Save kaldas/970825 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class Yahttp | |
| { | |
| public static $host; | |
| public static $port; | |
| public static $currdir; | |
| public static $path; | |
| public static $html; | |
| private static $sock; | |
| private static $ip; | |
| private function connectToHost() | |
| { | |
| self::$ip = gethostbyname(self::$host); | |
| self::$sock = fsockopen(self::$ip, self::$port); | |
| for($c = 1;$c != 4 && !self::$sock;$c++) | |
| { | |
| self::$sock = fsockopen(self::$ip, self::$port); | |
| sleep($c); | |
| } | |
| if(!self::$sock) | |
| die("failed to connect to host ".self::$host); | |
| } | |
| public function makeGetRequest() | |
| { | |
| self::connectToHost(); | |
| $packet.= "GET ".self::$path."/".self::$currdir." HTTP/1.1\r\n"; | |
| $packet.= "Host: ".self::$host."\r\n"; | |
| $packet.= "Connection: Close\r\n"; | |
| $packet.= "Accept-Encoding: text/html\r\n\r\n"; | |
| fputs(self::$sock,$packet); | |
| self::$html = ""; | |
| while(!feof(self::$sock)) | |
| self::$html .= fgets(self::$sock, 256); | |
| fclose(self::$sock); | |
| } | |
| public function getResponseCode() | |
| { | |
| self::makeGetRequest(); | |
| $resultFirstLine = explode("\n",self::$html); | |
| if(stristr($resultFirstLine[0],"400")) | |
| { | |
| $output = "DIR: ".self::$currdir." ERROR: MALFORMED PACKET"; | |
| } | |
| elseif(!stristr($resultFirstLine[0],"404")) //only displays the response code if its not a 404 | |
| { | |
| $output = "DIR: ".self::$currdir." RESULT: ".$resultFirstLine[0]; | |
| } | |
| return $output; | |
| } | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment