}
/* }}} */
-/* {{{ proto bool session_set_save_handler(string open, string close, string read, string write, string destroy, string gc, string create_sid)
- Sets user-level functions */
-static PHP_FUNCTION(session_set_save_handler)
+static int save_handler_check_session() {
+ if (PS(session_status) == php_session_active) {
+ php_error_docref(NULL, E_WARNING, "Session save handler cannot be changed when a session is active");
+ return FAILURE;
+ }
+
+ if (SG(headers_sent)) {
+ php_error_docref(NULL, E_WARNING, "Session save handler cannot be changed after headers have already been sent");
+ return FAILURE;
+ }
+
+ return SUCCESS;
+}
+
+ static inline void set_user_save_handler_ini(void) {
+ zend_string *ini_name, *ini_val;
+
+ ini_name = zend_string_init("session.save_handler", sizeof("session.save_handler") - 1, 0);
+ ini_val = zend_string_init("user", sizeof("user") - 1, 0);
+ PS(set_handler) = 1;
+ zend_alter_ini_entry(ini_name, ini_val, PHP_INI_USER, PHP_INI_STAGE_RUNTIME);
+ PS(set_handler) = 0;
+ zend_string_release_ex(ini_val, 0);
+ zend_string_release_ex(ini_name, 0);
+ }
+
+/* {{{ Sets user-level functions */
+PHP_FUNCTION(session_set_save_handler)
{
zval *args = NULL;
int i, num_args, argc = ZEND_NUM_ARGS();
- zend_string *ini_name, *ini_val;
- if (PS(session_status) == php_session_active) {
- php_error_docref(NULL, E_WARNING, "Cannot change save handler when session is active");
- RETURN_FALSE;
- }
-
- if (SG(headers_sent)) {
- php_error_docref(NULL, E_WARNING, "Cannot change save handler when headers already sent");
- RETURN_FALSE;
- }
-
if (argc > 0 && argc <= 2) {
zval *obj = NULL;
zend_string *func_name;
}
}
- if (PS(mod) && PS(mod) != &ps_mod_user) {
- ini_name = zend_string_init("session.save_handler", sizeof("session.save_handler") - 1, 0);
- ini_val = zend_string_init("user", sizeof("user") - 1, 0);
- PS(set_handler) = 1;
- zend_alter_ini_entry(ini_name, ini_val, PHP_INI_USER, PHP_INI_STAGE_RUNTIME);
- PS(set_handler) = 0;
- zend_string_release_ex(ini_val, 0);
- zend_string_release_ex(ini_name, 0);
+ if (save_handler_check_session() == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ /* remove shutdown function */
+ remove_user_shutdown_function("session_shutdown", sizeof("session_shutdown") - 1);
+
+ if (!PS(mod) || PS(mod) != &ps_mod_user) {
+ set_user_save_handler_ini();
}
for (i = 0; i < argc; i++) {