From b4d9b70c6ebad6fd648671b97ea5cb40bfb32665 Mon Sep 17 00:00:00 2001 From: "Frank M. Kromann" Date: Mon, 3 Dec 2001 05:10:10 +0000 Subject: [PATCH] Make php_setcookie available from shared extensions --- ext/standard/head.c | 39 +++++++++++++++++++++++---------------- ext/standard/head.h | 1 + 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/ext/standard/head.c b/ext/standard/head.c index 8794411af57..614fa9f6235 100644 --- a/ext/standard/head.c +++ b/ext/standard/head.c @@ -63,26 +63,12 @@ PHPAPI int php_header() } - -/* php_set_cookie(name, value, expires, path, domain, secure) */ -/* {{{ proto bool setcookie(string name [, string value [, int expires [, string path [, string domain [, bool secure]]]]]) - Send a cookie */ -PHP_FUNCTION(setcookie) +PHPAPI int php_setcookie(char *name, int name_len, char *value, int value_len, time_t expires, char *path, int path_len, char *domain, int domain_len, int secure TSRMLS_DC) { char *cookie, *encoded_value = NULL; - char *name, *value = NULL, *path = NULL, *domain = NULL; int len=sizeof("Set-Cookie: "); time_t t; char *dt; - time_t expires = 0; - zend_bool secure = 0; - int name_len, value_len, path_len, domain_len; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|slssb", &name, - &name_len, &value, &value_len, &expires, &path, - &path_len, &domain, &domain_len, &secure) == FAILURE) { - return; - } len += name_len; if (value) { @@ -98,6 +84,7 @@ PHP_FUNCTION(setcookie) len += domain_len; } cookie = emalloc(len + 100); + if (value && value_len == 0) { /* * MSIE doesn't delete a cookie when you set it to a null value @@ -134,7 +121,27 @@ PHP_FUNCTION(setcookie) strcat(cookie, "; secure"); } - if (sapi_add_header(cookie, strlen(cookie), 0)==SUCCESS) { + return sapi_add_header(cookie, strlen(cookie), 0); +} + + +/* php_set_cookie(name, value, expires, path, domain, secure) */ +/* {{{ proto bool setcookie(string name [, string value [, int expires [, string path [, string domain [, bool secure]]]]]) + Send a cookie */ +PHP_FUNCTION(setcookie) +{ + char *name, *value = NULL, *path = NULL, *domain = NULL; + time_t expires = 0; + zend_bool secure = 0; + int name_len, value_len, path_len, domain_len; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|slssb", &name, + &name_len, &value, &value_len, &expires, &path, + &path_len, &domain, &domain_len, &secure) == FAILURE) { + return; + } + + if (php_setcookie(name, name_len, value, value_len, expires, path, path_len, domain, domain_len, secure TSRMLS_CC) == SUCCESS) { RETVAL_TRUE; } else { RETVAL_FALSE; diff --git a/ext/standard/head.h b/ext/standard/head.h index 1de1a5b3793..959ff0d837e 100644 --- a/ext/standard/head.h +++ b/ext/standard/head.h @@ -27,5 +27,6 @@ PHP_FUNCTION(setcookie); PHP_FUNCTION(headers_sent); PHPAPI int php_header(void); +PHPAPI int php_setcookie(char *name, int name_len, char *value, int value_len, time_t expires, char *path, int path_len, char *domain, int domain_len, int secure TSRMLS_DC); #endif