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

Patch max-age.diff for *General Issues Bug #72071

Patch version 2016-04-21 21:41 UTC

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

Developer: bfrance

--- ext/standard/head.c.orig	2016-03-30 23:35:38.000000000 +0000
+++ ext/standard/head.c	2016-04-21 20:58:50.231897897 +0000
@@ -122,6 +122,7 @@
 	} else {
 		snprintf(cookie, len + 100, "Set-Cookie: %s=%s", name, value ? encoded_value : "");
 		if (expires > 0) {
+		        time_t now;
 			const char *p;
 			char tsdelta[13];
 			strlcat(cookie, "; expires=", len + 100);
@@ -138,9 +139,16 @@
 			strlcat(cookie, dt, len + 100);
 			efree(dt);
 
-			snprintf(tsdelta, sizeof(tsdelta), "%li", (long) difftime(expires, time(NULL)));
-			strlcat(cookie, "; Max-Age=", len + 100);
-			strlcat(cookie, tsdelta, len + 100);
+			now = (time_t)sapi_get_request_time(TSRMLS_C);
+
+			if (expires <= now) {
+			    strlcat(cookie, "; Max-Age=0", len + 100);
+			}
+			else {
+			    snprintf(tsdelta, sizeof(tsdelta), "%li", (long) difftime(expires, now));
+			    strlcat(cookie, "; Max-Age=", len + 100);
+			    strlcat(cookie, tsdelta, len + 100);
+			}
 		}
 	}
 
--- ext/standard/tests/network/setcookie.phpt.orig	2016-04-21 20:37:49.933294979 +0000
+++ ext/standard/tests/network/setcookie.phpt	2016-04-21 20:38:04.604303163 +0000
@@ -26,7 +26,7 @@
 	'Set-Cookie: name=space+value',
 	'Set-Cookie: name=value',
 	'Set-Cookie: name=value; expires='.date('D, d-M-Y H:i:s', $tsp).' GMT; Max-Age=5',
-	'Set-Cookie: name=value; expires='.date('D, d-M-Y H:i:s', $tsn).' GMT; Max-Age=-6',
+	'Set-Cookie: name=value; expires='.date('D, d-M-Y H:i:s', $tsn).' GMT; Max-Age=0',
 	'Set-Cookie: name=value; expires='.date('D, d-M-Y H:i:s', $tsc).' GMT; Max-Age=0',
 	'Set-Cookie: name=value; path=/path/',
 	'Set-Cookie: name=value; domain=domain.tld',
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 20:01:29 2024 UTC