summaryrefslogtreecommitdiff
path: root/ext/standard/head.c
diff options
context:
space:
mode:
authorLars Strojny <lstrojny@php.net>2013-01-06 03:22:44 +0100
committerLars Strojny <lstrojny@php.net>2013-01-06 03:22:44 +0100
commitec2fff80e768dfb04aa393c06a2b1a42a9e871ff (patch)
treec0a9b54c899b3c5d878e1d29ddc8d67b973def09 /ext/standard/head.c
parentf3824ad16644c53645e7428d2e838278f5a0e1c4 (diff)
downloadphp-git-ec2fff80e768dfb04aa393c06a2b1a42a9e871ff.tar.gz
Bug #23955: allow specifiy max age for setcookie()
Diffstat (limited to 'ext/standard/head.c')
-rw-r--r--ext/standard/head.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/ext/standard/head.c b/ext/standard/head.c
index 97f61f2bef..fa578175b1 100644
--- a/ext/standard/head.c
+++ b/ext/standard/head.c
@@ -40,11 +40,11 @@ PHP_FUNCTION(header)
{
zend_bool rep = 1;
sapi_header_line ctr = {0};
-
+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|bl", &ctr.line,
&ctr.line_len, &rep, &ctr.response_code) == FAILURE)
return;
-
+
sapi_header_op(rep ? SAPI_HEADER_REPLACE:SAPI_HEADER_ADD, &ctr TSRMLS_CC);
}
/* }}} */
@@ -80,7 +80,7 @@ PHPAPI int php_setcookie(char *name, int name_len, char *value, int value_len, t
char *dt;
sapi_header_line ctr = {0};
int result;
-
+
if (name && strpbrk(name, "=,; \t\r\n\013\014") != NULL) { /* man isspace for \013 and \014 */
zend_error( E_WARNING, "Cookie names cannot contain any of the following '=,; \\t\\r\\n\\013\\014'" );
return FAILURE;
@@ -111,18 +111,19 @@ PHPAPI int php_setcookie(char *name, int name_len, char *value, int value_len, t
cookie = emalloc(len + 100);
if (value && value_len == 0) {
- /*
+ /*
* MSIE doesn't delete a cookie when you set it to a null value
* so in order to force cookies to be deleted, even on MSIE, we
* pick an expiry date in the past
*/
dt = php_format_date("D, d-M-Y H:i:s T", sizeof("D, d-M-Y H:i:s T")-1, 1, 0 TSRMLS_CC);
- snprintf(cookie, len + 100, "Set-Cookie: %s=deleted; expires=%s", name, dt);
+ snprintf(cookie, len + 100, "Set-Cookie: %s=deleted; expires=%s; Max-Age=0", name, dt);
efree(dt);
} else {
snprintf(cookie, len + 100, "Set-Cookie: %s=%s", name, value ? encoded_value : "");
if (expires > 0) {
const char *p;
+ char tsdelta[13];
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 */
@@ -136,6 +137,10 @@ PHPAPI int php_setcookie(char *name, int name_len, char *value, int value_len, t
}
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);
}
}
@@ -237,11 +242,11 @@ PHP_FUNCTION(headers_sent)
ZVAL_LONG(arg2, line);
case 1:
zval_dtor(arg1);
- if (file) {
+ if (file) {
ZVAL_STRING(arg1, file, 1);
} else {
ZVAL_STRING(arg1, "", 1);
- }
+ }
break;
}