From 88ed2002daf68baed8700c692778bf6f50eb8c5e Mon Sep 17 00:00:00 2001 From: Andrey Hristov Date: Tue, 29 Jun 1999 15:39:59 +0000 Subject: [PATCH] Added session expiration. --- ext/session/php_session.h | 1 + ext/session/session.c | 24 ++++++++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/ext/session/php_session.h b/ext/session/php_session.h index 740754a2fa4..7e946f101e6 100644 --- a/ext/session/php_session.h +++ b/ext/session/php_session.h @@ -78,6 +78,7 @@ typedef struct { char *save_path; char *session_name; char *id; + int lifetime; ps_module *mod; void *mod_data; HashTable vars; diff --git a/ext/session/session.c b/ext/session/session.c index 79483d15f2c..c2ea23ce134 100644 --- a/ext/session/session.c +++ b/ext/session/session.c @@ -47,6 +47,7 @@ #include "php_session.h" #include "ext/standard/md5.h" #include "ext/standard/php3_var.h" +#include "ext/standard/datetime.h" #ifdef ZTS @@ -79,6 +80,7 @@ PHP_INI_BEGIN() PHP_INI_ENTRY("session_auto_start", "0", PHP_INI_ALL, NULL) PHP_INI_ENTRY("session_gc_probability", "1", PHP_INI_ALL, NULL) PHP_INI_ENTRY("session_gc_maxlifetime", "1440", PHP_INI_ALL, NULL) + PHP_INI_ENTRY("session_lifetime", "60", PHP_INI_ALL, NULL) PHP_INI_END() @@ -252,16 +254,29 @@ static void _php_session_save_current_state(PSLS_D) PS(nr_open_sessions)--; } -#define COOKIE_FMT "Set-cookie: %s=%s" +#define COOKIE_FMT "Set-cookie: %s=%s" +#define COOKIE_EXPIRES "; expires=" static void _php_session_send_cookie(PSLS_D) { - int len; + int len; char *cookie; + char *date_fmt = NULL; + PSLS_FETCH(); len = strlen(PS(session_name)) + strlen(PS(id)) + sizeof(COOKIE_FMT); + if (PS(lifetime) > 0) { + date_fmt = php3_std_date(time(NULL) + PS(lifetime)); + len += sizeof(COOKIE_EXPIRES) + strlen(date_fmt); + } cookie = emalloc(len + 1); + snprintf(cookie, len, COOKIE_FMT, PS(session_name), PS(id)); + if (PS(lifetime) > 0) { + strcat(cookie, COOKIE_EXPIRES); + strcat(cookie, date_fmt); + efree(date_fmt); + } sapi_add_header(cookie, len); } @@ -555,9 +570,10 @@ static void php_rinit_session_globals(PSLS_D) zend_hash_init(&PS(vars), 0, NULL, NULL, 0); PS(save_path) = estrdup(INI_STR("session_save_path")); PS(session_name) = estrdup(INI_STR("session_name")); - PS(gc_probability) = INI_INT("gc_probability"); - PS(gc_maxlifetime) = INI_INT("gc_maxlifetime"); + PS(gc_probability) = INI_INT("session_gc_probability"); + PS(gc_maxlifetime) = INI_INT("session_gc_maxlifetime"); PS(id) = NULL; + PS(lifetime) = INI_INT("session_lifetime"); PS(nr_open_sessions) = 0; PS(mod_data) = NULL; }