[ Index ]
 

Code source de GeekLog 1.4.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/system/pear/PHP/Compat/Function/ -> get_headers.php (source)

   1  <?php
   2  // +----------------------------------------------------------------------+

   3  // | PHP Version 4                                                        |

   4  // +----------------------------------------------------------------------+

   5  // | Copyright (c) 1997-2004 The PHP Group                                |

   6  // +----------------------------------------------------------------------+

   7  // | This source file is subject to version 3.0 of the PHP license,       |

   8  // | that is bundled with this package in the file LICENSE, and is        |

   9  // | available at through the world-wide-web at                           |

  10  // | http://www.php.net/license/3_0.txt.                                  |

  11  // | If you did not receive a copy of the PHP license and are unable to   |

  12  // | obtain it through the world-wide-web, please send a note to          |

  13  // | license@php.net so we can mail you a copy immediately.               |

  14  // +----------------------------------------------------------------------+

  15  // | Authors: Aidan Lister <aidan@php.net>                                |

  16  // +----------------------------------------------------------------------+

  17  //

  18  // $Id: get_headers.php,v 1.1 2005/05/10 07:50:53 aidan Exp $

  19  
  20  
  21  /**

  22   * Replace get_headers()

  23   *

  24   * @category    PHP

  25   * @package     PHP_Compat

  26   * @link        http://php.net/function.get_headers

  27   * @author      Aeontech <aeontech@gmail.com>

  28   * @author      Cpurruc <cpurruc@fh-landshut.de>

  29   * @author      Aidan Lister <aidan@php.net>

  30   * @version     $Revision: 1.1 $

  31   * @since       PHP 5.0.0

  32   * @require     PHP 4.0.0 (user_error)

  33   */
  34  if (!function_exists('get_headers')) {
  35      function get_headers($url, $format = 0)
  36      {
  37          // Init

  38          $urlinfo = parse_url($url);
  39          $port    = isset($urlinfo['port']) ? $urlinfo['port'] : 80;
  40  
  41          // Connect

  42          $fp = fsockopen($urlinfo['host'], $port, $errno, $errstr, 30);
  43          if ($fp === false) {
  44              return false;
  45          }
  46                
  47          // Send request

  48          $head = 'HEAD ' . $urlinfo['path'] .
  49              (isset($urlinfo['query']) ? '?' . $urlinfo['query'] : '') .
  50              ' HTTP/1.0' . "\r\n" .
  51              'Host: ' . $urlinfo['host'] . "\r\n\r\n";
  52          fputs($fp, $head);
  53  
  54          // Read

  55          while (!feof($fp)) {
  56              if ($header = trim(fgets($fp, 1024))) {
  57                  list($key) = explode(':', $header);
  58  
  59                  if ($format === 1) {
  60                      // First element is the HTTP header type, such as HTTP 200 OK

  61                      // It doesn't have a separate name, so check for it

  62                      if ($key == $header) {
  63                          $headers[] = $header;
  64                      } else {
  65                          $headers[$key] = substr($header, strlen($key)+2);
  66                      }
  67                  } else {
  68                      $headers[] = $header;
  69                  }
  70              }
  71          }
  72  
  73          return $headers;
  74      }
  75  }
  76  
  77  ?>


Généré le : Wed Nov 21 12:27:40 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics