Request headers missing in PHP
I'm currently building a site and was planning on using pjax to move between pages for eye-candy, and to resuce the amount of javascript and CSS loading/parsing. However I've run into a problem. When PJax detects that the browser supports pushstate(), it injects an extra HTTP header in the request.
I can see this request using wireshark. It appears that pjax is appending paramters to the URL, but I can't see the custom headers:
GET /src/doku.php?id=Contacts&_pjax=%23pjax_content HTTP/1.1
Host: localhost
Connection: keep-alive
Accept: text/html, */*; q=0.01
X-Requested-With: XMLHttpRequest
X-PJAX: true
X-PJAX-Container: #pjax_content
User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.93 Safari/537.36
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Referer: http://localhost/src/doku.php?id=Contacts
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-GB,en-US;q=0.8,en;q=0.6
Cookie: DokuWiki=9d88cf8aa5922692577a7892124ca2cc
But in PHP, $_SERVER only contains:
array (
'PATH' => '/sbin:/usr/sbin:/bin:/usr/bin',
'USER' => 'apache',
'HOME' => '/var/www',
'FCGI_ROLE' => 'RESPONDER',
'QUERY_STRING' => 'id=Members',
'REQUEST_METHOD' => 'GET',
'CONTENT_TYPE' => '',
'CONTENT_LENGTH' => '',
'SCRIPT_NAME' => '/src/doku.php',
'REQUEST_URI' => '/src/doku.php?id=Members',
'DOCUMENT_URI' => '/src/doku.php',
'DOCUMENT_ROOT' => '/var/www/html',
'SERVER_PROTOCOL' => 'HTTP/1.1',
'GATEWAY_INTERFACE' => 'CGI/1.1',
'SERVER_SOFTWARE' => 'nginx/1.0.9',
'REMOTE_ADDR' => '127.0.0.1',
'REMOTE_PORT' => '37908',
'SERVER_ADDR' => '127.0.0.1',
'SERVER_PORT' => '80',
'SERVER_NAME' => '_',
'REDIRECT_STATUS' => '200',
'SCRIPT_FILENAME' => '/var/www/html/src/doku.php',
'HTTP_HOST' => 'localhost',
'HTTP_CONNECTION' => 'keep-alive',
'HTTP_CACHE_CONTROL' => 'max-age=0',
'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'HTTP_USER_AGENT' => 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.93 Safari/537.36',
'HTTP_ACCEPT_ENCODING' => 'gzip,deflate,sdch',
'HTTP_ACCEPT_LANGUAGE' => 'en-GB,en-US;q=0.8,en;q=0.6',
'HTTP_COOKIE' => 'DokuWiki=9d88cf8aa5922692577a7892124ca2cc',
'PHP_SELF' => '/src/doku.php',
'REQUEST_TIME' => 1370207676,
)
I've tried both Apache 2.2 + mod_php and Nginx 1.0.9 + php-fpm (in both instances PHP is 5.3.3). I was checking for $_SERVER['HTTP_X_PJAX'] (but looked at all the $_SERVER variables) and on Apache also checked with getallheaders(). (The example above is from Nginx + php=fpm).
I also repeated the experiment without the Suhosin extension loaded - no different.
I've lost both the headers and injected parameter! While it should be possible to amend the pjax code to use a cookie or fix the parameter thing, I'd like to know why it's doing this. A number of years ago, I had no problem with reading custom headers in PHP 4).
I'm currently building a site and was planning on using pjax to move between pages for eye-candy, and to resuce the amount of javascript and CSS loading/parsing. However I've run into a problem. When PJax detects that the browser supports pushstate(), it injects an extra HTTP header in the request.
I can see this request using wireshark. It appears that pjax is appending paramters to the URL, but I can't see the custom headers:
GET /src/doku.php?id=Contacts&_pjax=%23pjax_content HTTP/1.1
Host: localhost
Connection: keep-alive
Accept: text/html, */*; q=0.01
X-Requested-With: XMLHttpRequest
X-PJAX: true
X-PJAX-Container: #pjax_content
User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.93 Safari/537.36
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Referer: http://localhost/src/doku.php?id=Contacts
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-GB,en-US;q=0.8,en;q=0.6
Cookie: DokuWiki=9d88cf8aa5922692577a7892124ca2cc
But in PHP, $_SERVER only contains:
array (
'PATH' => '/sbin:/usr/sbin:/bin:/usr/bin',
'USER' => 'apache',
'HOME' => '/var/www',
'FCGI_ROLE' => 'RESPONDER',
'QUERY_STRING' => 'id=Members',
'REQUEST_METHOD' => 'GET',
'CONTENT_TYPE' => '',
'CONTENT_LENGTH' => '',
'SCRIPT_NAME' => '/src/doku.php',
'REQUEST_URI' => '/src/doku.php?id=Members',
'DOCUMENT_URI' => '/src/doku.php',
'DOCUMENT_ROOT' => '/var/www/html',
'SERVER_PROTOCOL' => 'HTTP/1.1',
'GATEWAY_INTERFACE' => 'CGI/1.1',
'SERVER_SOFTWARE' => 'nginx/1.0.9',
'REMOTE_ADDR' => '127.0.0.1',
'REMOTE_PORT' => '37908',
'SERVER_ADDR' => '127.0.0.1',
'SERVER_PORT' => '80',
'SERVER_NAME' => '_',
'REDIRECT_STATUS' => '200',
'SCRIPT_FILENAME' => '/var/www/html/src/doku.php',
'HTTP_HOST' => 'localhost',
'HTTP_CONNECTION' => 'keep-alive',
'HTTP_CACHE_CONTROL' => 'max-age=0',
'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'HTTP_USER_AGENT' => 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.93 Safari/537.36',
'HTTP_ACCEPT_ENCODING' => 'gzip,deflate,sdch',
'HTTP_ACCEPT_LANGUAGE' => 'en-GB,en-US;q=0.8,en;q=0.6',
'HTTP_COOKIE' => 'DokuWiki=9d88cf8aa5922692577a7892124ca2cc',
'PHP_SELF' => '/src/doku.php',
'REQUEST_TIME' => 1370207676,
)
I've tried both Apache 2.2 + mod_php and Nginx 1.0.9 + php-fpm (in both instances PHP is 5.3.3). I was checking for $_SERVER['HTTP_X_PJAX'] (but looked at all the $_SERVER variables) and on Apache also checked with getallheaders(). (The example above is from Nginx + php=fpm).
I also repeated the experiment without the Suhosin extension loaded - no different.
I've lost both the headers and injected parameter! While it should be possible to amend the pjax code to use a cookie or fix the parameter thing, I'd like to know why it's doing this. A number of years ago, I had no problem with reading custom headers in PHP 4).
No comments:
Post a Comment