webinteger powered by Trojan Online Marketing
Schnellsuche:
Check HTTP Status
Backlink Checker







 
Navigation: StartseiteSEO ToolsCheck HTTP StatusDokumentation

Check HTTP Status - Dokumentation

Unser Formular befindet sich auf der Seite 'check_http_status.php' und beinhalten das Formular sowie die Klasseneinbindung und Definition. Die eigentliche Arbeit übernimmt die Klasse '_class_status.php'.

Datei check_http_status.php
  1.  
  2. //*****************************************************************************************************************
  3. // Copyright by webinteger.net
  4. // Author: Günther Trojan / 2007
  5. //*****************************************************************************************************************
  6.  
  7. // Bei Submit
  8. if(isset($_POST["submit"])){
  9.  
  10. include("_class_status.php");
  11.  
  12. $http_status = new seo_tools;
  13. $http_status->get_http_status(trim($_POST["url"]));
  14.  
  15. // ERGEBNIS AUSGABE
  16. echo '<p style="color:#009900"><b>Das Ergebnis für '.trim($_POST["url"]).':</b><p>';
  17. echo '<p>';
  18. echo 'HTTP Status Line: <b>'.$http_status->array_http_status["Status-Line"].'</b><br>';
  19. echo 'HTTP Status: <b>'.$http_status->array_http_status["Status-Code"].'</b><br>';
  20. echo 'HTTP Version: <b>'.$http_status->array_http_status["HTTP-Version"].'</b><br>';
  21. echo 'Reason Phrase: <b>'.$http_status->array_http_status["Reason-Phrase"].'</b><br>';
  22. if($http_status->array_http_status["Status-Code"] == "301" || $http_status->array_http_status["Status-Code"] == "302"){
  23. echo 'Weiterleitung nach: <b>'.$http_status->array_http_status["Location"].'</b><br>';
  24. echo 'HTTP Status der Weiterleitung: <b>'.$http_status->array_http_status["Location-Status-Code"].'</b><br>';
  25. }
  26. echo "</p><br><br>";
  27. }
  28.  
  29. echo '<form action="" method="post">';
  30. echo '<p>URL: <small>(z.B.: http://www.IhreDomain.de</small>)<br>';
  31. echo '<input type="text" name="url" value="'.htmlspecialchars(stripslashes($_POST["url"])).'" style="width: 325px;">';
  32. echo '&nbsp;<input name="submit" type="submit" value="Check">';
  33. echo '</p></form>'
  34.  

In der Zeile 29 bis einschließlich 33 befindet sich unser Formular mit dem die URL abgefragt wird. Bei Übermittlung dessen, geht es in Zeile 8 Weiter. Unsere Klasse '_class_status.php' wird eingebunden. Das Ergebnis befindent sich im Array '$http_status->array_http_status'. Die Einzelheiten dessen, werden in Zeile 16 bis 26 dargestellt.

Nun zu unsere Klasse:

Klasse _class_status.php
  1.  
  2. //*****************************************************************************************************************
  3. // Copyright by webinteger.net
  4. // Author: Günther Trojan / 2007
  5. //*****************************************************************************************************************
  6.  
  7. <?php
  8. class seo_tools{
  9.  
  10. var $url;
  11. var $array_parse_url = array();
  12. var $user_agent = "webinteger.net";
  13. var $array_http_status = array();
  14.  
  15. //*****************************************************************************************************************
  16. // get_http_status
  17. //*****************************************************************************************************************
  18.  
  19. function get_http_status($url, $abbruch=false){
  20.  
  21. if(empty($url)) return FALSE;
  22. $this->url = $url;
  23. $this->array_parse_url = parse_url($this->url);
  24. if(!isset($this->array_parse_url["scheme"])) $this->url = "http://".$this->url;
  25. if(!isset($this->array_parse_url["port"])) $this->array_parse_url["port"] = 80;
  26. if(!isset($this->array_parse_url["path"])) $this->array_parse_url["path"] = "/";
  27.  
  28. $fp = @fsockopen($this->array_parse_url["host"], $this->array_parse_url["port"], $errno, $errstr, 15);
  29. if(!$fp){
  30. if($abbruch){
  31. $this->array_http_status["Location-Status-Code"] = "Seite nicht gefunden - Zeitüberschreitung";
  32. }else{
  33. $this->array_http_status["Status-Line"] = "Angegebene Seite nicht gefunden";
  34. $this->array_http_status["HTTP-Version"] = "-";
  35. $this->array_http_status["Status-Code"] = "408";
  36. $this->array_http_status["Reason-Phrase"] = "Zeitüberschreitung";
  37. }
  38. return;
  39. }else{
  40.  
  41. fputs($fp, "GET ".$this->array_parse_url["path"]." HTTP/1.1\r\n");
  42. fputs($fp, "Host: ".$this->array_parse_url["host"]."\r\n");
  43. fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
  44. fputs($fp, "Content-length: ".strlen($parameters). "\r\n");
  45. fputs($fp, "User-Agent: ".$this->user_agent."\r\n");
  46. fputs($fp, "Connection: close\r\n\r\n");
  47.  
  48. $head = "";
  49. while(!feof($fp)) $head.= fgets($fp, 1024);
  50. fclose($fp);
  51.  
  52. preg_match("=^(HTTP/\d+\.\d+) (\d{3}) ([^\r\n]*)=", $head, $treffer);
  53.  
  54. if($abbruch){
  55. $this->array_http_status["Location-Status-Code"] = $treffer[2];
  56. }else{
  57. $this->array_http_status["Status-Line"] = $treffer[0];
  58. $this->array_http_status["HTTP-Version"] = $treffer[1];
  59. $this->array_http_status["Status-Code"] = $treffer[2];
  60. $this->array_http_status["Reason-Phrase"] = $treffer[3];
  61.  
  62. $http_klassen = array("Informational", "Successful", "Redirection", "Client Error", "Server Error");
  63. $this->array_http_status["Response-Class"] = $http_klassen[$this->array_http_status["Status-Code"][0] - 1];
  64. preg_match_all("=^(.+): ([^\r\n]*)=m", $head, $treffer, PREG_SET_ORDER);
  65. foreach($treffer as $zeile){
  66. $this->array_http_status[$zeile[1]] = $zeile[2];
  67. }
  68. if($this->array_http_status["Status-Code"][0] == 3){
  69. $this->get_http_status($this->array_http_status["Location"], true);
  70. }
  71. }
  72. }
  73. return;
  74. }
  75. }
  76. ?>
  77.  
  78.  

Unsere Klasse besteht eigentlich nur aus einer Methode. Absichtlich existiert kein Konstruktor für diese Klasse. So ist es einfache die Klasse später wo anders zu integrieren. In Zeile 22 wird überprüft, ob auch eine URL eingegeben wurde. In Zeile 23 wird die URL geparst und für die Socket Verbindung aufbereitet. Die Variable 'abbruch' spielt dann eine Rolle, wenn bei der URL eine Umleitung ermittelt wird. Ist erfolgreich die Verbindung hergestellt "simulieren" wir in Zeile 41 bis 50 unseren Browser. Der daraus erfolgte Header wird von Zeile 52 bis 70 durch reguläre Ausdrücke zerlegt und in unser Array geschrieben. Handelt es sich um eine 3xx Weiterleitung, wird die Methode erneut in Zeile 68 aufgerufen (diesmal ist der Abbruch aktiviert) und den HTTP Status der Weiterleitungslocation ermittelt.

Autor: Troll