--- embedaddon/php/ext/standard/head.c 2012/02/21 23:48:02 1.1.1.1 +++ embedaddon/php/ext/standard/head.c 2014/06/15 20:03:57 1.1.1.4 @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2012 The PHP Group | + | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -15,7 +15,7 @@ | Author: Rasmus Lerdorf | +----------------------------------------------------------------------+ */ -/* $Id: head.c,v 1.1.1.1 2012/02/21 23:48:02 misho Exp $ */ +/* $Id: head.c,v 1.1.1.4 2014/06/15 20:03:57 misho Exp $ */ #include #include "php.h" @@ -31,7 +31,6 @@ #endif #include "php_globals.h" -#include "safe_mode.h" /* Implementation of the language Header() function */ @@ -123,7 +122,7 @@ PHPAPI int php_setcookie(char *name, int name_len, cha } else { snprintf(cookie, len + 100, "Set-Cookie: %s=%s", name, value ? encoded_value : ""); if (expires > 0) { - char *p; + const char *p; strlcat(cookie, "; expires=", len + 100); dt = php_format_date("D, d-M-Y H:i:s T", sizeof("D, d-M-Y H:i:s T")-1, expires, 0 TSRMLS_CC); /* check to make sure that the year does not exceed 4 digits in length */ @@ -132,7 +131,7 @@ PHPAPI int php_setcookie(char *name, int name_len, cha efree(dt); efree(cookie); efree(encoded_value); - zend_error(E_WARNING, "Expiry date cannot have a year greater then 9999"); + zend_error(E_WARNING, "Expiry date cannot have a year greater than 9999"); return FAILURE; } strlcat(cookie, dt, len + 100); @@ -221,15 +220,15 @@ PHP_FUNCTION(setrawcookie) PHP_FUNCTION(headers_sent) { zval *arg1 = NULL, *arg2 = NULL; - char *file=""; + const char *file=""; int line=0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|zz", &arg1, &arg2) == FAILURE) return; if (SG(headers_sent)) { - line = php_get_output_start_lineno(TSRMLS_C); - file = php_get_output_start_filename(TSRMLS_C); + line = php_output_get_start_lineno(TSRMLS_C); + file = php_output_get_start_filename(TSRMLS_C); } switch(ZEND_NUM_ARGS()) { @@ -278,6 +277,38 @@ PHP_FUNCTION(headers_list) } array_init(return_value); zend_llist_apply_with_argument(&SG(sapi_headers).headers, php_head_apply_header_list_to_hash, return_value TSRMLS_CC); +} +/* }}} */ + +/* {{{ proto long http_response_code([int response_code]) + Sets a response code, or returns the current HTTP response code */ +PHP_FUNCTION(http_response_code) +{ + 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; + } + + RETURN_LONG(SG(sapi_headers).http_response_code); } /* }}} */