sas Thu Feb 20 01:24:08 2003 EDT Modified files: (Branch: PHP_4_3) /php4/ext/session php_session.h session.c Log: MFH general urlencoding MFH session_regenerate_id, a change which is as important as the former one Index: php4/ext/session/php_session.h diff -u php4/ext/session/php_session.h:1.84.2.2 php4/ext/session/php_session.h:1.84.2.3 --- php4/ext/session/php_session.h:1.84.2.2 Mon Feb 10 20:16:03 2003 +++ php4/ext/session/php_session.h Thu Feb 20 01:24:08 2003 @@ -118,6 +118,8 @@ zend_bool use_only_cookies; zend_bool use_trans_sid; /* contains the INI value of whether to use trans-sid */ zend_bool apply_trans_sid; /* whether or not to enable trans-sid for the current request */ + int send_cookie; + int define_sid; } php_ps_globals; typedef php_ps_globals zend_ps_globals; @@ -129,6 +131,7 @@ PHP_FUNCTION(session_module_name); PHP_FUNCTION(session_save_path); PHP_FUNCTION(session_id); +PHP_FUNCTION(session_regenerate_id); PHP_FUNCTION(session_decode); PHP_FUNCTION(session_register); PHP_FUNCTION(session_unregister); Index: php4/ext/session/session.c diff -u php4/ext/session/session.c:1.336.2.6 php4/ext/session/session.c:1.336.2.7 --- php4/ext/session/session.c:1.336.2.6 Mon Feb 10 20:16:03 2003 +++ php4/ext/session/session.c Thu Feb 20 01:24:08 2003 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: session.c,v 1.336.2.6 2003/02/11 01:16:03 sas Exp $ */ +/* $Id: session.c,v 1.336.2.7 2003/02/20 06:24:08 sas Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -60,6 +60,7 @@ PHP_FE(session_module_name, NULL) PHP_FE(session_save_path, NULL) PHP_FE(session_id, NULL) + PHP_FE(session_regenerate_id, NULL) PHP_FE(session_decode, NULL) PHP_FE(session_register, NULL) PHP_FE(session_unregister, NULL) @@ -918,19 +919,47 @@ convert_to_string((*ppid)); \ PS(id) = estrndup(Z_STRVAL_PP(ppid), Z_STRLEN_PP(ppid)) +static void php_session_reset_id(TSRMLS_D) +{ + int module_number = PS(module_number); + + if (PS(send_cookie)) { + php_session_send_cookie(TSRMLS_C); + } + + /* if the SID constant exists, destroy it. */ + zend_hash_del(EG(zend_constants), "sid", sizeof("sid")); + + if (PS(define_sid)) { + smart_str var = {0}; + + smart_str_appends(&var, PS(session_name)); + smart_str_appendc(&var, '='); + smart_str_appends(&var, PS(id)); + smart_str_0(&var); + REGISTER_STRINGL_CONSTANT("SID", var.c, var.len, 0); + } else { + REGISTER_STRINGL_CONSTANT("SID", empty_string, 0, 0); + } + + if (PS(apply_trans_sid)) { + php_url_scanner_reset_vars(TSRMLS_C); + php_url_scanner_add_var(PS(session_name), strlen(PS(session_name)), +PS(id), strlen(PS(id)), 1 TSRMLS_CC); + } +} + PHPAPI void php_session_start(TSRMLS_D) { zval **ppid; zval **data; char *p; - int send_cookie = 1; - int define_sid = 1; - int module_number = PS(module_number); int nrand; int lensess; PS(apply_trans_sid) = PS(use_trans_sid); + PS(define_sid) = 1; + PS(send_cookie) = 1; if (PS(session_status) != php_session_none) return; @@ -950,8 +979,8 @@ lensess + 1, (void **) &ppid) == SUCCESS) { PPID2SID; PS(apply_trans_sid) = 0; - send_cookie = 0; - define_sid = 0; + PS(send_cookie) = 0; + PS(define_sid) = 0; } if (!PS(use_only_cookies) && !PS(id) && @@ -961,7 +990,7 @@ zend_hash_find(Z_ARRVAL_PP(data), PS(session_name), lensess + 1, (void **) &ppid) == SUCCESS) { PPID2SID; - send_cookie = 0; + PS(send_cookie) = 0; } if (!PS(use_only_cookies) && !PS(id) && @@ -971,7 +1000,7 @@ zend_hash_find(Z_ARRVAL_PP(data), PS(session_name), lensess + 1, (void **) &ppid) == SUCCESS) { PPID2SID; - send_cookie = 0; + PS(send_cookie) = 0; } } @@ -1004,42 +1033,22 @@ strstr(Z_STRVAL_PP(data), PS(extern_referer_chk)) == NULL) { efree(PS(id)); PS(id) = NULL; - send_cookie = 1; + PS(send_cookie) = 1; if (PS(use_trans_sid)) PS(apply_trans_sid) = 1; } php_session_initialize(TSRMLS_C); - if (!PS(use_cookies) && send_cookie) { + if (!PS(use_cookies) && PS(send_cookie)) { if (PS(use_trans_sid)) PS(apply_trans_sid) = 1; - send_cookie = 0; - } - - if (send_cookie) { - php_session_send_cookie(TSRMLS_C); + PS(send_cookie) = 0; } - /* if the SID constant exists, destroy it. */ - zend_hash_del(EG(zend_constants), "sid", sizeof("sid")); + php_session_reset_id(TSRMLS_C); - if (define_sid) { - smart_str var = {0}; - - smart_str_appendl(&var, PS(session_name), lensess); - smart_str_appendc(&var, '='); - smart_str_appends(&var, PS(id)); - smart_str_0(&var); - REGISTER_STRINGL_CONSTANT("SID", var.c, var.len, 0); - } else { - REGISTER_STRINGL_CONSTANT("SID", empty_string, 0, 0); - } - PS(session_status) = php_session_active; - if (PS(apply_trans_sid)) { - php_url_scanner_add_var(PS(session_name), strlen(PS(session_name)), PS(id), strlen(PS(id)), 0 TSRMLS_CC); - } php_session_cache_limiter(TSRMLS_C); @@ -1259,6 +1268,23 @@ } RETVAL_STRING(old, 0); +} +/* }}} */ + +/* {{{ proto string session_regenerate_id() + Update the current session id with a newly generated one. */ +PHP_FUNCTION(session_regenerate_id) +{ + if (PS(session_status) == php_session_active) { + if (PS(id)) efree(PS(id)); + + PS(id) = PS(mod)->s_create_sid(&PS(mod_data), NULL TSRMLS_CC); + + php_session_reset_id(TSRMLS_C); + + RETURN_TRUE; + } + RETURN_FALSE; } /* }}} */
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php