views:

163

answers:

3

Hi, I've run into a problem on a server running php 5.1.6 - the code i use to detect ajax requests isn't working as the $_SERVER['HTTP_X_REQUESTED_WITH'] variable is missing from the $_SERVER array. The same code works fine on php 5.2 and in firebug i can see the headers include X-Requested-With XMLHttpRequest. Anyone know any more about this issue and how I can get round it? Thanks in advance.

A: 

You are having some kind of a redirect either in your files or in your .htaccess that clears this header.

Ivo Sabev
I can't see where this might be happening - I've emptied my .htaccess file and have tested for the $_SERVER['HTTP_X_REQUESTED_WITH'] variable in the constructor of the controller being requested and it isn't there. Very strange...
kenny99
+2  A: 

Since php is installed as an apache module you can use apache_request_headers() for debugging purposes.
Does the header show up in debuglog.txt when you add

function dbgLogRequest() {
  $s = date('Y-m-d H:i:s') . "\n request headers";
  foreach( apache_request_headers() as $name=>$value ) {
    $s .= "\n  $name: $value";
  }
  $s .= "\n____\n\n";

  file_put_contents('debuglog.txt', $s, FILE_APPEND);
}

dbgLogRequest();

to your code?

VolkerK
Thanks for this VolkerK - useful to know for any future issues I have. Managed to get this issue fixed - the site where i was experiencing the issue was a preview version of the site via Plesk. I moved the site to a dedicated domain and the issue disappeared. very strange
kenny99
+1  A: 

The only things I can dig up are:

  • IE browser may not be sending the header
  • If you have a redirect then the header does not get forwarded
  • Inline frames for file uploading don't use ajax so don't send this header

Thats all... Not much else out there...

zaf