]> granicus.if.org Git - php/commitdiff
Added a parameter to php_setcookie to toggle URL encoding of the cookie data
authorBrian France <bfrance@php.net>
Wed, 20 Aug 2003 20:51:10 +0000 (20:51 +0000)
committerBrian France <bfrance@php.net>
Wed, 20 Aug 2003 20:51:10 +0000 (20:51 +0000)
Added the function setrawcookie that turns off URL encoding of the cookie data
Changed setcookie to turn on the URL encoding of the cookie data

ext/standard/basic_functions.c
ext/standard/head.c
ext/standard/head.h

index b8c77bfc74da3bb18b7de72b8027f69edef56631..9566fa9f8f53fa6392b98d37bb20da6422d6a676 100644 (file)
@@ -607,6 +607,7 @@ function_entry basic_functions[] = {
        PHP_FE(restore_include_path,                                                                                    NULL)
 
        PHP_FE(setcookie,                                                                                                               NULL)
+       PHP_FE(setrawcookie,                                                                                                    NULL)
        PHP_FE(header,                                                                                                                  NULL)
        PHP_FE(headers_sent,  first_and_second__args_force_ref)
 
index 542dfe47ac584ed36d1bffefca994f33067eca24..04d1a8608dc5edc3e464fa4df20434b73b35a6f2 100644 (file)
@@ -65,7 +65,7 @@ PHPAPI int php_header(TSRMLS_D)
 }
 
 
-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)
+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, int url_encode TSRMLS_DC)
 {
        char *cookie, *encoded_value = NULL;
        int len=sizeof("Set-Cookie: ");
@@ -75,11 +75,14 @@ PHPAPI int php_setcookie(char *name, int name_len, char *value, int value_len, t
        int result;
        
        len += name_len;
-       if (value) {
+       if (value && url_encode) {
                int encoded_value_len;
 
                encoded_value = php_url_encode(value, value_len, &encoded_value_len);
                len += encoded_value_len;
+       } else if ( value ) {
+               encoded_value = estrdup(value);
+               len += value_len;
        }
        if (path) {
                len += path_len;
@@ -150,7 +153,30 @@ PHP_FUNCTION(setcookie)
                return;
        }
 
-       if (php_setcookie(name, name_len, value, value_len, expires, path, path_len, domain, domain_len, secure TSRMLS_CC) == SUCCESS) {
+       if (php_setcookie(name, name_len, value, value_len, expires, path, path_len, domain, domain_len, secure, 1 TSRMLS_CC) == SUCCESS) {
+               RETVAL_TRUE;
+       } else {
+               RETVAL_FALSE;
+       }
+}
+/* }}} */
+
+/* {{{ proto bool setrawcookie(string name [, string value [, int expires [, string path [, string domain [, bool secure]]]]])
+   Send a cookie with no url encoding of the value */
+PHP_FUNCTION(setrawcookie)
+{
+       char *name, *value = NULL, *path = NULL, *domain = NULL;
+       long 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, 0 TSRMLS_CC) == SUCCESS) {
                RETVAL_TRUE;
        } else {
                RETVAL_FALSE;
index b964f033ef0d3055ecc08b9179d575bd9691d471..15c8dccf24499cddfbae7f6df970b64dc658a33e 100644 (file)
 extern PHP_RINIT_FUNCTION(head);
 PHP_FUNCTION(header);
 PHP_FUNCTION(setcookie);
+PHP_FUNCTION(setrawcookie);
 PHP_FUNCTION(headers_sent);
 
 PHPAPI int php_header(TSRMLS_D);
-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);
+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, int url_encode TSRMLS_DC);
 
 #endif