skip to Main Content

will apache_request_headers function work on NGINX Web
Server. If not what is function for NGINX parallel to it

2

Answers


  1. Some people have written their own functions on the PHP docs site.

    https://www.php.net/manual/en/function.apache-request-headers.php

    <?php
    if( !function_exists('apache_request_headers') ) {
    
    function apache_request_headers() {
      $arh = array();
      $rx_http = '/AHTTP_/';
      foreach($_SERVER as $key => $val) {
        if( preg_match($rx_http, $key) ) {
          $arh_key = preg_replace($rx_http, '', $key);
          $rx_matches = array();
          // do some nasty string manipulations to restore the original letter case
          // this should work in most cases
          $rx_matches = explode('_', $arh_key);
          if( count($rx_matches) > 0 and strlen($arh_key) > 2 ) {
            foreach($rx_matches as $ak_key => $ak_val) $rx_matches[$ak_key] = ucfirst($ak_val);
            $arh_key = implode('-', $rx_matches);
          }
          $arh[$arh_key] = $val;
        }
      }
      return( $arh );
      }
    }
    

    See if that helps (haven’t tried it).

    Login or Signup to reply.
  2. As per the documentation:
    https://www.php.net/manual/en/function.apache-request-headers.php

    Fetches all HTTP request headers from the current request. Works in the Apache, FastCGI, CLI, FPM and NSAPI server module in Netscape/iPlanet/SunONE webservers.

    If you’re running PHP via an FPM socket on UNIX, or using the FastCGI interface, this function will work. The fact is begins with apache is misleading, but is hardly atypical of PHP function naming.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search