summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDerick Rethans <derick@php.net>2002-06-21 09:31:21 +0000
committerDerick Rethans <derick@php.net>2002-06-21 09:31:21 +0000
commit6869cb3f5a907500d9553c978fc491748585d9db (patch)
treea40530b71f58a94b359254c223d380c2ffb7f2be
parent0f4ccfaa27a52b916a78fedae167aaa03808b372 (diff)
downloadphp-git-6869cb3f5a907500d9553c978fc491748585d9db.tar.gz
- Added a new parameter to the header() function which overrides the HTTP
response code. @- Added a new parameter to the header() function which overrides the HTTP @ response code. (Derick)
-rw-r--r--ext/standard/head.c11
-rw-r--r--main/SAPI.c13
-rw-r--r--main/SAPI.h4
-rw-r--r--sapi/pi3web/pi3web_sapi.c2
-rw-r--r--sapi/tux/php_tux.c2
5 files changed, 18 insertions, 14 deletions
diff --git a/ext/standard/head.c b/ext/standard/head.c
index e69905725a..4e4e74c914 100644
--- a/ext/standard/head.c
+++ b/ext/standard/head.c
@@ -35,19 +35,20 @@
/* Implementation of the language Header() function */
-/* {{{ proto void header(string header [, bool replace])
+/* {{{ proto void header(string header [, bool replace, [int http_response_code]])
Sends a raw HTTP header */
PHP_FUNCTION(header)
{
char *header;
int header_len;
zend_bool replace = 1;
+ int http_code = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &header,
- &header_len, &replace) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|bl", &header,
+ &header_len, &replace, &http_code) == FAILURE) {
return;
}
- sapi_add_header_ex(header, header_len, 1, replace TSRMLS_CC);
+ sapi_add_header_ex(header, header_len, 1, replace, http_code TSRMLS_CC);
}
/* }}} */
@@ -121,7 +122,7 @@ PHPAPI int php_setcookie(char *name, int name_len, char *value, int value_len, t
strcat(cookie, "; secure");
}
- return sapi_add_header_ex(cookie, strlen(cookie), 0, 0 TSRMLS_CC);
+ return sapi_add_header_ex(cookie, strlen(cookie), 0, 0, 0 TSRMLS_CC);
}
diff --git a/main/SAPI.c b/main/SAPI.c
index 0c6d2fe21e..0077e277fa 100644
--- a/main/SAPI.c
+++ b/main/SAPI.c
@@ -393,7 +393,7 @@ static int sapi_find_matching_header(void *element1, void *element2)
/* This function expects a *duplicated* string, that was previously emalloc()'d.
* Pointers sent to this functions will be automatically freed by the framework.
*/
-SAPI_API int sapi_add_header_ex(char *header_line, uint header_line_len, zend_bool duplicate, zend_bool replace TSRMLS_DC)
+SAPI_API int sapi_add_header_ex(char *header_line, uint header_line_len, zend_bool duplicate, zend_bool replace, int http_response_code TSRMLS_DC)
{
int retval;
sapi_header_struct sapi_header;
@@ -462,11 +462,11 @@ SAPI_API int sapi_add_header_ex(char *header_line, uint header_line_len, zend_bo
efree(mimetype);
SG(sapi_headers).send_default_content_type = 0;
} else if (!STRCASECMP(header_line, "Location")) {
- if (SG(sapi_headers).http_response_code < 300 ||
- SG(sapi_headers).http_response_code > 307) {
- /* Return a Found Redirect if one is not already specified */
+ if (SG(sapi_headers).http_response_code < 300 ||
+ SG(sapi_headers).http_response_code > 307) {
+ /* Return a Found Redirect if one is not already specified */
SG(sapi_headers).http_response_code = 302;
- }
+ }
} else if (!STRCASECMP(header_line, "WWW-Authenticate")) { /* HTTP Authentication */
int newlen;
char *result, *newheader;
@@ -547,6 +547,9 @@ SAPI_API int sapi_add_header_ex(char *header_line, uint header_line_len, zend_bo
}
}
+ if (http_response_code) {
+ SG(sapi_headers).http_response_code = http_response_code;
+ }
if (sapi_module.header_handler) {
retval = sapi_module.header_handler(&sapi_header, &SG(sapi_headers) TSRMLS_CC);
} else {
diff --git a/main/SAPI.h b/main/SAPI.h
index 8a5edfcbe4..c335b32795 100644
--- a/main/SAPI.h
+++ b/main/SAPI.h
@@ -133,9 +133,9 @@ SAPI_API void sapi_activate(TSRMLS_D);
SAPI_API void sapi_deactivate(TSRMLS_D);
SAPI_API void sapi_initialize_empty_request(TSRMLS_D);
-SAPI_API int sapi_add_header_ex(char *header_line, uint header_line_len, zend_bool duplicate, zend_bool replace TSRMLS_DC);
+SAPI_API int sapi_add_header_ex(char *header_line, uint header_line_len, zend_bool duplicate, zend_bool replace, int http_response_code TSRMLS_DC);
#define sapi_add_header(header_line, header_line_len, duplicate) \
- sapi_add_header_ex((header_line), (header_line_len), (duplicate), 1 TSRMLS_CC)
+ sapi_add_header_ex((header_line), (header_line_len), (duplicate), 1, 0 TSRMLS_CC)
SAPI_API int sapi_send_headers(TSRMLS_D);
SAPI_API void sapi_free_header(sapi_header_struct *sapi_header);
SAPI_API void sapi_handle_post(void *arg TSRMLS_DC);
diff --git a/sapi/pi3web/pi3web_sapi.c b/sapi/pi3web/pi3web_sapi.c
index 2f49cdca72..a7176a1b2a 100644
--- a/sapi/pi3web/pi3web_sapi.c
+++ b/sapi/pi3web/pi3web_sapi.c
@@ -424,7 +424,7 @@ DWORD PHP4_wrapper(LPCONTROL_BLOCK lpCB)
break;
case PHP_MODE_INDENT:
header_line = (char *)estrdup("Content-Type: text/plain");
- sapi_add_header_ex(header_line, strlen(header_line), 1, 1 TSRMLS_CC);
+ sapi_add_header_ex(header_line, strlen(header_line), 1, 1, 0 TSRMLS_CC);
if ( open_file_for_scanning( &file_handle TSRMLS_CC ) == SUCCESS )
{
zend_indent();
diff --git a/sapi/tux/php_tux.c b/sapi/tux/php_tux.c
index 16a7be8133..d2da64882a 100644
--- a/sapi/tux/php_tux.c
+++ b/sapi/tux/php_tux.c
@@ -195,7 +195,7 @@ static void sapi_tux_register_variables(zval *track_vars_array TSRMLS_DC)
sprintf(buf, "Server: %s", TUXAPI_version);
- sapi_add_header_ex(buf, strlen(buf), 1, 0 TSRMLS_CC);
+ sapi_add_header_ex(buf, strlen(buf), 1, 0, 0 TSRMLS_CC);
php_register_variable("PHP_SELF", SG(request_info).request_uri, track_vars_array TSRMLS_CC);
php_register_variable("SERVER_SOFTWARE", TUXAPI_version, track_vars_array TSRMLS_CC);
php_register_variable("GATEWAY_INTERFACE", "CGI/1.1", track_vars_array TSRMLS_CC);