]> granicus.if.org Git - php/commitdiff
- Added a new parameter to the header() function which overrides the HTTP
authorDerick Rethans <derick@php.net>
Fri, 21 Jun 2002 09:31:21 +0000 (09:31 +0000)
committerDerick Rethans <derick@php.net>
Fri, 21 Jun 2002 09:31:21 +0000 (09:31 +0000)
  response code.
@- Added a new parameter to the header() function which overrides the HTTP
@  response code. (Derick)

ext/standard/head.c
main/SAPI.c
main/SAPI.h
sapi/pi3web/pi3web_sapi.c
sapi/tux/php_tux.c

index e69905725a1e3df261b66b3d0fd1fe982f2d55ff..4e4e74c9148965e2c65ad83147311a7b0675f891 100644 (file)
 
 
 /* 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);
 }
 
 
index 0c6d2fe21e751815160b137bb7f4cea8ae9afbd4..0077e277fa7452a414f69b8fe731e64ede974afb 100644 (file)
@@ -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 {
index 8a5edfcbe41e89418bae5c7af3a763f6093357ff..c335b327952adc9917ab910e6e271e5aeb13e0e7 100644 (file)
@@ -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);
index 2f49cdca72f8425bab8f83083e52827d1943a988..a7176a1b2a084ac25d8173ac430c354e1b343318 100644 (file)
@@ -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();
index 16a7be81336017184727b8c48a3eabb667144eb1..d2da64882a876326cb1f07e33588b063f93a506d 100644 (file)
@@ -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);