Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:37642 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 35299 invoked from network); 14 May 2008 02:40:55 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 May 2008 02:40:55 -0000 Authentication-Results: pb1.pair.com smtp.mail=brianm@dealnews.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=brianm@dealnews.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain dealnews.com designates 72.5.90.27 as permitted sender) X-PHP-List-Original-Sender: brianm@dealnews.com X-Host-Fingerprint: 72.5.90.27 smtp.dealnews.com Linux 2.5 (sometimes 2.4) (4) Received: from [72.5.90.27] ([72.5.90.27:55480] helo=smtp.dealnews.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 48/68-09150-6315A284 for ; Tue, 13 May 2008 22:40:54 -0400 Received: (qmail 4407 invoked from network); 14 May 2008 02:40:52 -0000 Received: from unknown (HELO mail.dealnews.com) (10.1.10.7) by -H with ESMTPS (DHE-RSA-AES256-SHA encrypted); 14 May 2008 02:40:52 -0000 Received: (qmail 20893 invoked from network); 14 May 2008 02:40:51 -0000 Received: from 17.2.1.10.in-addr.arpa (brianm@10.1.2.17) by -H with ESMTPA; 14 May 2008 02:40:51 -0000 Message-ID: <482A5133.6020702@dealnews.com> Date: Tue, 13 May 2008 21:40:51 -0500 User-Agent: Thunderbird 2.0.0.14 (Macintosh/20080421) MIME-Version: 1.0 To: PHP Developers Mailing List Content-Type: multipart/mixed; boundary="------------080604080600040203020104" Subject: Resending session cookies patch From: brianm@dealnews.com (Brian Moon) --------------080604080600040203020104 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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/ --------------080604080600040203020104 Content-Type: text/plain; name="session_patch.txt" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="session_patch.txt" --- 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; } --------------080604080600040203020104--