Created
December 21, 2011 12:11
-
-
Save tomsseisums/1505803 to your computer and use it in GitHub Desktop.
PHP and headers and... aye, it sucks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// a function to check if a specific header exists, current way due to headers_list() returning numeric array | |
function header_exists($lookup) | |
{ | |
$headers = headers_list(); | |
foreach($headers as $header){ | |
if(0 !== stripos($header, $lookup)){ // or other lookup... | |
continue; | |
}else{ | |
return true; | |
} | |
} | |
return false; | |
} | |
// what if the function would return headers in a key => value fashion? | |
function header_exists($lookup) | |
{ | |
return array_key_exists($lookup, headers_list()); | |
} | |
// the thing is that, AFAIK, every single header follows the `Key: Value` pattern, why such a weird result? | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment