From 9f782a73e8b68017104f74f94a94a0aa1af6e0b2 Mon Sep 17 00:00:00 2001 From: Kalle Sommer Nielsen Date: Tue, 12 Jul 2011 03:56:32 +0000 Subject: [PATCH] Changed http_response_code() to be able to set a response code --- NEWS | 3 ++- ext/standard/basic_functions.c | 3 ++- ext/standard/head.c | 22 +++++++++++++++++++--- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/NEWS b/NEWS index 480bc72f52..ae0a795ad5 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,4 @@ -PHP NEWS +PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? 2011, PHP 5.4.0 Alpha 2 - General improvements: @@ -16,6 +16,7 @@ PHP NEWS . Lowered default value for Process Manager. FR #54098. (fat) - Improved core functions: + . Changed http_response_code() to be able to set a response code. (Kalle) . Fixed crypt_blowfish handling of 8-bit characters. (Stas) (CVE-2011-2483) . Fixed bug#55084 (Function registered by header_register_callback is called only once per process). (Hannes) diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index cb749a7e00..6af19d6d18 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -1481,7 +1481,8 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO(arginfo_headers_list, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO(arginfo_http_response_code, 0) +ZEND_BEGIN_ARG_INFO_EX(arginfo_http_response_code, 0, 0, 0) + ZEND_ARG_INFO(0, response_code) ZEND_END_ARG_INFO() /* }}} */ /* {{{ html.c */ diff --git a/ext/standard/head.c b/ext/standard/head.c index 2f0ad9e3f6..ec5ed95657 100644 --- a/ext/standard/head.c +++ b/ext/standard/head.c @@ -280,14 +280,30 @@ PHP_FUNCTION(headers_list) } /* }}} */ -/* {{{ proto long http_response_code() - Returns the current HTTP response code */ +/* {{{ proto long http_response_code([int response_code]) + Sets a response code, or returns the current HTTP response code */ PHP_FUNCTION(http_response_code) { - if (zend_parse_parameters_none() == FAILURE) { + long response_code = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &response_code) == FAILURE) { return; } + if (response_code) + { + long old_response_code; + + old_response_code = SG(sapi_headers).http_response_code; + SG(sapi_headers).http_response_code = response_code; + + if (old_response_code) { + RETURN_LONG(old_response_code); + } + + RETURN_TRUE; + } + if (!SG(sapi_headers).http_response_code) { RETURN_FALSE; } -- 2.40.0