php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login

Patch Fixes-setcookie-to-only-send-one-Set-Cookie-header-per-header-name for *General Issues Bug #67736

Patch version 2014-08-31 17:13 UTC

Return to Bug #67736 | Download this patch
Patch Revisions:

Developer: florian@margaine.com

diff --git a/ext/standard/head.c b/ext/standard/head.c
index eca032a..a99e76c 100644
--- a/ext/standard/head.c
+++ b/ext/standard/head.c
@@ -91,6 +91,18 @@ PHPAPI int php_setcookie(char *name, int name_len, char *value, int value_len, t
 		return FAILURE;
 	}
 
+	if (SG(cookies) == NULL) {
+		ALLOC_HASHTABLE(SG(cookies));
+		zend_hash_init(SG(cookies), 0, NULL, NULL, 0);
+	}
+
+	if (zend_hash_exists(SG(cookies), name, name_len) == 1) {
+		zend_error( E_WARNING, "setcookie() cannot be used twice with the same name" );
+		return FAILURE;
+	}
+
+	zend_hash_add_empty_element(SG(cookies), name, name_len);
+
 	len += name_len;
 	if (value && url_encode) {
 		int encoded_value_len;
diff --git a/main/SAPI.h b/main/SAPI.h
index 990ca69..e186a4c 100644
--- a/main/SAPI.h
+++ b/main/SAPI.h
@@ -37,9 +37,9 @@
 
 #ifdef PHP_WIN32
 #	ifdef SAPI_EXPORTS
-#		define SAPI_API __declspec(dllexport) 
+#		define SAPI_API __declspec(dllexport)
 #	else
-#		define SAPI_API __declspec(dllimport) 
+#		define SAPI_API __declspec(dllimport)
 #	endif
 #elif defined(__GNUC__) && __GNUC__ >= 4
 #	define SAPI_API __attribute__ ((visibility("default")))
@@ -136,6 +136,7 @@ typedef struct _sapi_globals_struct {
 	zval *callback_func;
 	zend_fcall_info_cache fci_cache;
 	zend_bool callback_run;
+	HashTable *cookies;
 } sapi_globals_struct;
 
 
@@ -156,7 +157,7 @@ SAPI_API void sapi_initialize_empty_request(TSRMLS_D);
 END_EXTERN_C()
 
 /*
- * This is the preferred and maintained API for 
+ * This is the preferred and maintained API for
  * operating on HTTP headers.
  */
 
@@ -165,7 +166,7 @@ END_EXTERN_C()
  *
  *     sapi_header_line ctr = {0};
  */
- 
+
 typedef struct {
 	char *line; /* If you allocated this, you need to free it yourself */
 	uint line_len;
@@ -266,7 +267,7 @@ struct _sapi_module_struct {
 	int (*get_target_gid)(gid_t * TSRMLS_DC);
 
 	unsigned int (*input_filter)(int arg, char *var, char **val, unsigned int val_len, unsigned int *new_val_len TSRMLS_DC);
-	
+
 	void (*ini_defaults)(HashTable *configuration_hash);
 	int phpinfo_as_text;
 
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Fri Dec 06 14:01:25 2019 UTC