-1

PHP's $_SERVER['HTTP_IF_NONE_MATCH'] is always empty however Firefox's Web Developer Network Requests tab shows the request header as being If-Modified-Since: "Tue, 27 Jun 2017 09:08:23 GMT". Cache is not disabled and my .htaccess file contains the following:

RewriteEngine on
RewriteRule .* - [E=HTTP_IF_NONE_MATCH:%{HTTP:If-None-Match}]

How do I get PHP's $_SERVER['HTTP_IF_NONE_MATCH'] to return the request header properly or how do I access that request header in an alternative manner? I came across getenv('HTTP_IF_MODIFIED_SINCE') though that didn't return anything either. Is it possible there is something in the php.ini file that needs to be changed? It is a fairly fresh server setup.

John
  • 1
  • 13
  • 98
  • 177
  • Duplicate of https://stackoverflow.com/questions/10847157/handling-if-modified-since-header-in-a-php-script – vrijdenker Jun 27 '17 at 10:33

1 Answers1

0

You should add a If-None-Match http header to your server. If you do so the HTTP_IF_NONE_MATCH server variable should contain the value of the set If-None-Match header.

curl http://my/endpoint --header 'If-None-Match: "my-custom-etag-value"'
danopz
  • 3,310
  • 5
  • 31
  • 42
  • Could you please use standard terms like client and server? Also I'm *not* using cURL for this, it's a request in a browser. – John Jun 27 '17 at 10:26
  • Sure, but how should I explain this for some random http clients? – danopz Jun 27 '17 at 10:30
  • Okay, so if I need to send an `If-None-Match` *request header* how do I get PHP and a *browser* to do this? What specifically triggers that? As in not using cURL (as fun as cURL can be). – John Jun 27 '17 at 10:32
  • Wait do you want to handle this manually or for static responses/files? Or maybe an api? – danopz Jun 27 '17 at 10:36
  • 1
    The request is to a PHP file that determines the `filemtime()` of the actual file where data is stored. So I suppose the answer is yes, I have to do this manually. – John Jun 27 '17 at 10:37