diff options
author | Frank M. Kromann <fmk@php.net> | 2001-12-03 05:10:10 +0000 |
---|---|---|
committer | Frank M. Kromann <fmk@php.net> | 2001-12-03 05:10:10 +0000 |
commit | b4d9b70c6ebad6fd648671b97ea5cb40bfb32665 (patch) | |
tree | 06d6726851a9c7d63de5b5bd0914243e12637800 | |
parent | ad1cb8205bddffdab1d268d35d213deacba9f85e (diff) | |
download | php-git-b4d9b70c6ebad6fd648671b97ea5cb40bfb32665.tar.gz |
Make php_setcookie available from shared extensions
-rw-r--r-- | ext/standard/head.c | 39 | ||||
-rw-r--r-- | 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 8794411af5..614fa9f623 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 1de1a5b379..959ff0d837 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 |