note 74592 added to function.apache-request-headers
| From: | callum85 at notspam dot msn dot com | Date: | Thu, 19 Apr 2007 06:07:05 +0000 |
| Subject: | note 74592 added to function.apache-request-headers | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-125561@lists.php.net to get a copy of this message | ||
There is a simple way to get request headers from Apache even on PHP running as a CGI. As far as I
know, it's the only way to get the headers "If-Modified-Since" and
"If-None-Match" when apache_request_headers() isn't available. You need mod_rewrite,
which most web hosts seem to have enabled. Put this in an .htacess file in your web root:
RewriteEngine on
RewriteRule .* - [E=HTTP_IF_MODIFIED_SINCE:%{HTTP:If-Modified-Since}]
RewriteRule .* - [E=HTTP_IF_NONE_MATCH:%{HTTP:If-None-Match}]
The headers are then available in PHP as
<?php
$_SERVER['HTTP_IF_MODIFIED_SINCE'];
$_SERVER['HTTP_IF_NONE_MATCH'];
?>
I've tested this on PHP/5.1.6, on both Apache/2.2.3/Win32 and Apache/2.0.54/Unix, and it works
perfectly.
Note: if you use RewriteRules already for clean URLs, you need to put the above rules AFTER your
existing ones.
----
Server IP: 69.147.83.197
Probable Submitter: 89.240.202.62
----
Manual Page -- http://www.php.net/manual/en/function.apache-request-headers.php
Edit -- https://master.php.net/note/edit/74592
Del: integrated -- https://master.php.net/note/delete/74592/integrated
Del: useless -- https://master.php.net/note/delete/74592/useless
Del: bad code -- https://master.php.net/note/delete/74592/bad+code
Del: spam -- https://master.php.net/note/delete/74592/spam
Del: non-english -- https://master.php.net/note/delete/74592/non-english
Del: in docs -- https://master.php.net/note/delete/74592/in+docs
Del: other reasons-- https://master.php.net/note/delete/74592
Reject -- https://master.php.net/note/reject/74592
Search -- https://master.php.net/manage/user-notes.php