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 Link to comment https://forums.phpfreaks.com/topic/17004-feedback-on-class-that-collects-headers/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.