1

I encountered a problem, I am developing a website with php, I used to work on the nginx, where I can tell an ajax request by the $_SERVER['HTTP_X_REQUESTED_WITH'] constant.

Recently I switched to apache2.4, here I encountered an embarrassing problem, $_SERVER['HTTP_X_REQUESTED_WITH'] constant is missing, after googling I know I can tell an ajax get request by the function apache_request_headers(), however it does not work on the ajax post request.

Can someone help me? Thanks a lot

Sachin PATIL
  • 745
  • 1
  • 9
  • 16
David
  • 41
  • 4
  • If i remember correctly and it hasen'T change you can add the header in your ajax request. comething like http://stackoverflow.com/questions/7686827/how-can-i-add-a-custom-http-header-to-ajax-request-with-js-or-jquery – Louis Loudog Trottier Mar 28 '17 at 02:09

1 Answers1

0

Try below code:

<?php
    function getRequestHeaders() {
        $headers = array();
        foreach($_SERVER as $key => $value) {

          $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 />\n";
    }
Sachin PATIL
  • 745
  • 1
  • 9
  • 16
  • THX, but it seems that only $_SERVER['HTTP_X_REQUESTED_WITH'] is enough, thanks anyway. – David Mar 30 '17 at 08:48