Re-JeeP Posted August 9, 2006 Share Posted August 9, 2006 Hi!I have made a class that collects the headers a server sends when you visit it threw port 80.Because I'm new to OOP I'd want some feedback on my class.[code]<?phpclass headers{ var $server; var $port; var $fp; function headers($server, $port = 80) { $this->server = $server; $this->port = $port; } function get_headers() { $this->fp = $this->connect(); if($this->fp) { $this->send_request(); $output = $this->save(); $this->close(); return $this->trim_output($output); } else { return array("Failed!"); } } function trim_output($output) { $rows = explode("\n", $output); foreach($rows as $value) { if($value == "\r") { return $headers; } else { $headers[] = htmlentities($value); } } return $headers; } function connect() { return fsockopen($this->server, $this->port, $errno, $errstr, 5); } function send_request() { return fputs($this->fp, "GET / HTTP/1.1\r\nHost: $this->server\r\n\r\n"); } function save() { while(!feof($this->fp)) { $result .= fgets($this->fp, 128); } return $result; } function close() { return fclose($this->fp); }}$headers = new headers("domain.com");$get = $headers->get_headers();foreach($get as $value) { echo $value."<br />"; }?>[/code]Thanks!// Johan Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.