Skip to content

Instantly share code, notes, and snippets.

@yesasha
Last active April 22, 2018 14:38
Show Gist options
  • Save yesasha/eac5ae5da3c339c09e476ffe0274e28f to your computer and use it in GitHub Desktop.
Save yesasha/eac5ae5da3c339c09e476ffe0274e28f to your computer and use it in GitHub Desktop.
http_responce_code function polyfill #2 from http://php.net/manual/en/function.http-response-code.php
<?php
/**
* http_responce_code function polyfill.
* http://php.net/manual/en/function.http-response-code.php
*
* @param number $code
* @return string
*/
if (!function_exists('http_response_code')) {
function http_response_code ($code = NULL) {
$prev_code = (isset($GLOBALS['http_response_code']) ? $GLOBALS['http_response_code'] : 200);
if ($code === NULL) {
return $prev_code;
}
header('X-Temporary-Header: none', true, $code);
header_remove('X-Temporary-Header');
$GLOBALS['http_response_code'] = $code;
return $prev_code;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment