• <legend id='ZyMER'><style id='ZyMER'><dir id='ZyMER'><q id='ZyMER'></q></dir></style></legend>
    1. <tfoot id='ZyMER'></tfoot>

          <bdo id='ZyMER'></bdo><ul id='ZyMER'></ul>
        <i id='ZyMER'><tr id='ZyMER'><dt id='ZyMER'><q id='ZyMER'><span id='ZyMER'><b id='ZyMER'><form id='ZyMER'><ins id='ZyMER'></ins><ul id='ZyMER'></ul><sub id='ZyMER'></sub></form><legend id='ZyMER'></legend><bdo id='ZyMER'><pre id='ZyMER'><center id='ZyMER'></center></pre></bdo></b><th id='ZyMER'></th></span></q></dt></tr></i><div id='ZyMER'><tfoot id='ZyMER'></tfoot><dl id='ZyMER'><fieldset id='ZyMER'></fieldset></dl></div>

        <small id='ZyMER'></small><noframes id='ZyMER'>

        如何在 PHP 中读取任何请求标头

        时间:2024-08-22

            <tbody id='4pevc'></tbody>
        • <small id='4pevc'></small><noframes id='4pevc'>

          • <bdo id='4pevc'></bdo><ul id='4pevc'></ul>
            • <i id='4pevc'><tr id='4pevc'><dt id='4pevc'><q id='4pevc'><span id='4pevc'><b id='4pevc'><form id='4pevc'><ins id='4pevc'></ins><ul id='4pevc'></ul><sub id='4pevc'></sub></form><legend id='4pevc'></legend><bdo id='4pevc'><pre id='4pevc'><center id='4pevc'></center></pre></bdo></b><th id='4pevc'></th></span></q></dt></tr></i><div id='4pevc'><tfoot id='4pevc'></tfoot><dl id='4pevc'><fieldset id='4pevc'></fieldset></dl></div>

                <legend id='4pevc'><style id='4pevc'><dir id='4pevc'><q id='4pevc'></q></dir></style></legend>

                  <tfoot id='4pevc'></tfoot>
                  本文介绍了如何在 PHP 中读取任何请求标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我应该如何阅读 PHP 中的任何标头?

                  How should I read any header in PHP?

                  例如自定义标头:X-Requested-With.

                  推荐答案

                  IF:你只需要一个header,而不是all headers,最快的方法是:

                  IF: you only need a single header, instead of all headers, the quickest method is:

                  <?php
                  // Replace XXXXXX_XXXX with the name of the header you need in UPPERCASE (and with '-' replaced by '_')
                  $headerStringValue = $_SERVER['HTTP_XXXXXX_XXXX'];
                  


                  ELSE IF:您将 PHP 作为 Apache 模块运行,或者从 PHP 5.4 开始,使用 FastCGI(简单方法):


                  ELSE IF: you run PHP as an Apache module or, as of PHP 5.4, using FastCGI (simple method):

                  apache_request_headers()

                  <?php
                  $headers = apache_request_headers();
                  
                  foreach ($headers as $header => $value) {
                      echo "$header: $value <br />
                  ";
                  }
                  


                  ELSE: 在任何其他情况下,您都可以使用(用户态实现):


                  ELSE: In any other case, you can use (userland implementation):

                  <?php
                  function getRequestHeaders() {
                      $headers = array();
                      foreach($_SERVER as $key => $value) {
                          if (substr($key, 0, 5) <> 'HTTP_') {
                              continue;
                          }
                          $header = str_replace(' ', '-', ucwords(str_replace('_', ' ', strtolower(substr($key, 5)))));
                          $headers[$header] = $value;
                      }
                      return $headers;
                  }
                  
                  $headers = getRequestHeaders();
                  
                  foreach ($headers as $header => $value) {
                      echo "$header: $value <br />
                  ";
                  }
                  


                  另请参阅:
                  getallheaders() - (PHP >= 5.4) 跨平台版本 apache_request_headers()的别名apache_response_headers() - 获取所有 HTTP 响应标头.
                  headers_list() - 获取要发送的标头列表.


                  See Also:
                  getallheaders() - (PHP >= 5.4) cross platform edition Alias of apache_request_headers() apache_response_headers() - Fetch all HTTP response headers.
                  headers_list() - Fetch a list of headers to be sent.

                  这篇关于如何在 PHP 中读取任何请求标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:PHP file_get_contents() 和设置请求标头 下一篇:使用 header() 强制使用 php 下载文件

                  相关文章

                1. <legend id='EuTV9'><style id='EuTV9'><dir id='EuTV9'><q id='EuTV9'></q></dir></style></legend>
                  <i id='EuTV9'><tr id='EuTV9'><dt id='EuTV9'><q id='EuTV9'><span id='EuTV9'><b id='EuTV9'><form id='EuTV9'><ins id='EuTV9'></ins><ul id='EuTV9'></ul><sub id='EuTV9'></sub></form><legend id='EuTV9'></legend><bdo id='EuTV9'><pre id='EuTV9'><center id='EuTV9'></center></pre></bdo></b><th id='EuTV9'></th></span></q></dt></tr></i><div id='EuTV9'><tfoot id='EuTV9'></tfoot><dl id='EuTV9'><fieldset id='EuTV9'></fieldset></dl></div>

                  <small id='EuTV9'></small><noframes id='EuTV9'>

                2. <tfoot id='EuTV9'></tfoot>
                    <bdo id='EuTV9'></bdo><ul id='EuTV9'></ul>