home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 4 / hacker04 / 04_HACK04.ISO / src / PHP / getheaders.php3.txt < prev    next >
Encoding:
Text File  |  2002-05-06  |  1.0 KB  |  48 lines

  1. get_headers 
  2.  
  3. An alternative to the get_all_headers() function for those who either don't have Apache, or are running PHP3 as a CGI 
  4.  
  5.  
  6. <?php
  7.  
  8. #
  9. #
  10. #  arr_get_headers()
  11. #  Returns an associative array of client request headers
  12. #
  13. #  str_get_headers()
  14. #  Returns a string  of the form 'var: val\n' containing the 
  15. #  client request headers. It is meant as an example for those who
  16. #  do not want the overhead of parsing the headers twice.
  17. #
  18. #
  19. #  Todo:
  20. #  - Parse or remove HTTP_GET_VARS, HTTP_POST_VARS and HTTP_COOKIE_VARS
  21. #    if they exist.
  22. #
  23. #  v0.1
  24. #  2000/03/15
  25. #  James Corbett
  26. #
  27. #
  28. function arr_get_headers() {
  29.   while ( list( $var, $val) = each( $GLOBALS)) {
  30.     if ( substr( $var, 0, 4) == "HTTP") {
  31.       $headers[$var] = $val;
  32.     }
  33.   }
  34.   return $headers;
  35. }
  36.  
  37. function str_get_headers() {
  38.   $headers = "";
  39.   while ( list( $var, $val) = each( $GLOBALS)) {
  40.     if ( substr( $var, 0, 4) == "HTTP") {
  41.       $headers .= sprintf( "%s: %s\n", $var, $val);
  42.     }
  43.   }
  44.   return $headers;
  45. }
  46.  
  47. ?>
  48.