Here is a patch that will add an ini setting (session.cookie_resend) to resend session cookies whenever a session is started. The point of this is to keep a cookie's expiration fresh as users use a site. Currently, once a session is started, it will expire after cookie_lifetime no matter what. For my applications, I need that cookie to only expire after cookie_lifetime of non use. I also added a function called session_send_cookie() that will send the cookie right then in case you don't have access to the ini settings or want to make that customized based on events in your application.

The only caveat of this is that currently session_send_cookie() will send the Set-Cookie header every time it is called. There is no flag in the _php_ps_globals struct to indicate that a cookie has been sent other than PS(send_cookie). However, I can't rely on that because if the session is found and session.cookie_resend is 0 PS(send_cookie) is set to 0 already. I could add a new flag (cookie_sent?) and track that anywhere that php_session_send_cookie is called or even inside php_session_send_cookie. But, the coding style of this file did not seem to favor altering PS() inside that function. It does not currently check PS(send_cookie). It simply just fires off the Set-Cookie header.

Thoughts?

--

Brian Moon
Senior Developer/Engineer
------------------------------
When you care enough to spend the very least.
http://dealnews.com/

--- php_session.h.orig  2008-05-13 21:08:54.000000000 -0500
+++ php_session.h       2008-05-13 21:08:09.000000000 -0500
@@ -104,6 +104,7 @@
        char *cookie_domain;
        zend_bool  cookie_secure;
        zend_bool  cookie_httponly;
+       zend_bool  cookie_resend;
        ps_module *mod;
        void *mod_data;
        php_session_status session_status;
@@ -153,6 +154,7 @@
 PHP_FUNCTION(session_set_cookie_params);
 PHP_FUNCTION(session_get_cookie_params);
 PHP_FUNCTION(session_write_close);
+PHP_FUNCTION(session_send_cookie);

 #ifdef ZTS
 #define PS(v) TSRMG(ps_globals_id, php_ps_globals *, v)

--- session.c.orig      2008-05-13 21:09:00.000000000 -0500
+++ session.c   2008-05-13 21:06:20.000000000 -0500
@@ -77,6 +77,7 @@
        PHP_FE(session_set_cookie_params, NULL)
        PHP_FE(session_get_cookie_params, NULL)
        PHP_FE(session_write_close,       NULL)
+       PHP_FE(session_send_cookie,       NULL)
        PHP_FALIAS(session_commit, session_write_close, NULL)
        {NULL, NULL, NULL}
 };
@@ -194,6 +195,7 @@
        STD_PHP_INI_ENTRY("session.cookie_domain",      "",          
PHP_INI_ALL, OnUpdateString, cookie_domain,      php_ps_globals,    ps_globals)
        STD_PHP_INI_BOOLEAN("session.cookie_secure",    "",          
PHP_INI_ALL, OnUpdateBool,   cookie_secure,      php_ps_globals,    ps_globals)
        STD_PHP_INI_BOOLEAN("session.cookie_httponly",  "",          
PHP_INI_ALL, OnUpdateBool,   cookie_httponly,    php_ps_globals,    ps_globals)
+       STD_PHP_INI_BOOLEAN("session.cookie_resend",    "0",         
PHP_INI_ALL, OnUpdateBool,   cookie_resend,      php_ps_globals,    ps_globals)
        STD_PHP_INI_BOOLEAN("session.use_cookies",      "1",         
PHP_INI_ALL, OnUpdateBool,   use_cookies,        php_ps_globals,    ps_globals)
        STD_PHP_INI_BOOLEAN("session.use_only_cookies", "0",         
PHP_INI_ALL, OnUpdateBool,   use_only_cookies,   php_ps_globals,    ps_globals)
        STD_PHP_INI_ENTRY("session.referer_check",      "",          
PHP_INI_ALL, OnUpdateString, extern_referer_chk, php_ps_globals,    ps_globals)
@@ -1148,6 +1150,17 @@
        sapi_add_header_ex(ncookie.c, ncookie.len, 0, 0 TSRMLS_CC);
 }

+/* {{{ proto void session_send_cookie(void)
+   Sends the cookie back to the browser */
+PHP_FUNCTION(session_send_cookie)
+{
+       if (PS(use_cookies)) {
+               php_session_send_cookie(TSRMLS_C);
+               PS(send_cookie) = 0;
+       }
+}
+/* }}} */
+
 PHPAPI ps_module *_php_find_ps_module(char *name TSRMLS_DC)
 {
        ps_module *ret = NULL;
@@ -1259,7 +1272,9 @@
                                        lensess + 1, (void **) &ppid) == 
SUCCESS) {
                        PPID2SID;
                        PS(apply_trans_sid) = 0;
-                       PS(send_cookie) = 0;
+                       if(!PS(cookie_resend)){
+                               PS(send_cookie) = 0;
+                       }
                        PS(define_sid) = 0;
                }



-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to