Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /data/sites/web/breulsorg/data/ZendFramework-1.11.7/library/Zend/Cache/Backend.php on line 66

Warning: Cannot modify header information - headers already sent by (output started at /data/sites/web/breulsorg/data/ZendFramework-1.11.7/library/Zend/Cache/Backend.php:66) in /data/sites/web/breulsorg/data/breulslog.live/application/modules/frontend/Bootstrap.php on line 15
Breuls.log / Fetching HTTP request headers in PHP
Ik ben Peter Breuls. Ik schrijf webapplicaties in PHP, filmreviews en onregelmatig iets op deze weblog. Welkom!
Onder de naam Devize ben ik beschikbaar als developer of consultant voor websites of webapplicaties.
Ik ben werkzaam als Administrator bij online community FOK! en als Lead Developer bij frontoffice-leverancier SIMgroep.

Fetching HTTP request headers in PHP

Tech / Web developmentreageer

Well, that was easy. I was looking for a way to fetch HTTP request headers in PHP, for the implementation of Conditional GET in an RSS module. PHP has this function, apache_request_headers(), which returns an array containing all the headers you could possibly need. Problem solved!

But; when the software you're working on (in my case a content management system) has to work on both Linux/Apache and Windows/IIS servers, there's a bit of a problem: Apache-functions won't work if there's no Apache to work with. Fortunately, you don't need functions to fetch specific headers: PHP has already gathered them for you.

When a client requests a PHP-driven page on your web server, you can check for request headers in the $_SERVER array. For instance, the If-Modified-Since header is stored in $_SERVER['HTTP_IF_MODIFIED_SINCE']. This will work for every header you can think of: PHP just converts them all to the right variable. A header This-One-Doesnt-Exist becomes $_SERVER['THIS_ONE_DOESNT_EXIST'] in PHP code. Just like that!


Deprecated: Function create_function() is deprecated in /data/sites/web/breulsorg/data/ZendFramework-1.11.7/library/Zend/Form/Element.php on line 319