]> granicus.if.org Git - php/commitdiff
- Fixed some inconsistencies with the behaviour of sessions. Changed session_start...
authorJani Taskinen <jani@php.net>
Wed, 6 Aug 2008 05:34:55 +0000 (05:34 +0000)
committerJani Taskinen <jani@php.net>
Wed, 6 Aug 2008 05:34:55 +0000 (05:34 +0000)
ext/session/session.c
ext/session/tests/session_decode_variation3.phpt
ext/session/tests/session_encode_variation3.phpt
ext/session/tests/session_encode_variation4.phpt
ext/session/tests/session_encode_variation5.phpt
ext/session/tests/session_encode_variation7.phpt
ext/session/tests/session_encode_variation8.phpt

index 8a959b84cf6f225d061fa7092a60dbedcaab7817..f254579f7cb871b95ec5402fb6913d80ea7f23f9 100644 (file)
@@ -508,7 +508,10 @@ static PHP_INI_MH(OnUpdateSaveHandler) /* {{{ */
                        err_type = E_ERROR;
                }
 
-               php_error_docref(NULL TSRMLS_CC, err_type, "Cannot find save handler %s", new_value);
+               /* Do not output error when restoring ini options. */
+               if (stage != ZEND_INI_STAGE_DEACTIVATE) {
+                       php_error_docref(NULL TSRMLS_CC, err_type, "Cannot find save handler '%s'", new_value);
+               }
                return FAILURE;
        }
        PS(mod) = tmp;
@@ -517,20 +520,6 @@ static PHP_INI_MH(OnUpdateSaveHandler) /* {{{ */
 }
 /* }}} */
 
-static PHP_INI_MH(OnUpdateTransSid) /* {{{ */
-{
-       SESSION_CHECK_ACTIVE_STATE;
-
-       if (!strncasecmp(new_value, "on", sizeof("on"))) {
-               PS(use_trans_sid) = (zend_bool) 1;
-       } else {
-               PS(use_trans_sid) = (zend_bool) atoi(new_value);
-       }
-
-       return SUCCESS;
-}
-/* }}} */
-
 static PHP_INI_MH(OnUpdateSerializer) /* {{{ */
 {
        const ps_serializer *tmp;
@@ -547,7 +536,10 @@ static PHP_INI_MH(OnUpdateSerializer) /* {{{ */
                        err_type = E_ERROR;
                }
 
-               php_error_docref(NULL TSRMLS_CC, err_type, "Cannot find serialization handler '%s'", new_value);
+               /* Do not output error when restoring ini options. */
+               if (stage != ZEND_INI_STAGE_DEACTIVATE) {
+                       php_error_docref(NULL TSRMLS_CC, err_type, "Cannot find serialization handler '%s'", new_value);
+               }
                return FAILURE;
        }
        PS(serializer) = tmp;
@@ -556,6 +548,20 @@ static PHP_INI_MH(OnUpdateSerializer) /* {{{ */
 }
 /* }}} */
 
+static PHP_INI_MH(OnUpdateTransSid) /* {{{ */
+{
+       SESSION_CHECK_ACTIVE_STATE;
+
+       if (!strncasecmp(new_value, "on", sizeof("on"))) {
+               PS(use_trans_sid) = (zend_bool) 1;
+       } else {
+               PS(use_trans_sid) = (zend_bool) atoi(new_value);
+       }
+
+       return SUCCESS;
+}
+/* }}} */
+
 static PHP_INI_MH(OnUpdateSaveDir) /* {{{ */
 {
        /* Only do the safemode/open_basedir check at runtime */
@@ -1236,30 +1242,42 @@ PHPAPI void php_session_start(TSRMLS_D) /* {{{ */
 {
        zval **ppid;
        zval **data;
-       char *p;
+       char *p, *value;
        int nrand;
        int lensess;
 
        PS(apply_trans_sid) = PS(use_trans_sid);
 
-       if (PS(session_status) != php_session_none) {
-               if (PS(session_status) == php_session_disabled) {
-                       char *value;
+       switch (PS(session_status)) {
+               case php_session_active:
+                       php_error(E_NOTICE, "A session had already been started - ignoring session_start()");
+                       return;
+                       break;
 
+               case php_session_disabled:
                        value = zend_ini_string("session.save_handler", sizeof("session.save_handler"), 0);
-
-                       if (value) {
-                               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot find save handler %s", value);
-                       } else {
-                               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot find unknown save handler");
+                       if (!PS(mod) && value) {
+                               PS(mod) = _php_find_ps_module(value TSRMLS_CC);
+                               if (!PS(mod)) {
+                                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot find save handler '%s' - session startup failed", value);
+                                       return;
+                               }
                        }
-                       return;
-               }
-               php_error(E_NOTICE, "A session had already been started - ignoring session_start()");
-               return;
-       } else {
-               PS(define_sid) = 1;
-               PS(send_cookie) = 1;
+                       value = zend_ini_string("session.serialize_handler", sizeof("session.serialize_handler"), 0);
+                       if (!PS(serializer) && value) {
+                               PS(serializer) = _php_find_ps_serializer(value TSRMLS_CC);
+                               if (!PS(serializer)) {
+                                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot find serialization handler '%s' - session startup failed", value);
+                                       return;
+                               }
+                       }
+                       PS(session_status) = php_session_none;
+                       /* fallthrough */
+
+               default:
+               case php_session_none:
+                       PS(define_sid) = 1;
+                       PS(send_cookie) = 1;
        }
 
        lensess = strlen(PS(session_name));
@@ -1560,7 +1578,6 @@ static PHP_FUNCTION(session_save_path)
        if (name) {
                if (memchr(name, '\0', name_len) != NULL) {
                        php_error_docref(NULL TSRMLS_CC, E_WARNING, "The save_path cannot contain NULL characters");
-
                        zval_dtor(return_value);
                        RETURN_FALSE;
                }
@@ -1762,6 +1779,10 @@ static PHP_FUNCTION(session_start)
 {
        /* skipping check for non-zero args for performance reasons here ?*/
        php_session_start(TSRMLS_C);
+
+       if (PS(session_status) != php_session_active) {
+               RETURN_FALSE;
+       }
        RETURN_TRUE;
 }
 /* }}} */
@@ -1778,7 +1799,6 @@ static PHP_FUNCTION(session_destroy)
 }
 /* }}} */
 
-
 /* {{{ proto void session_unset(void) U
    Unset all registered variables */
 static PHP_FUNCTION(session_unset)
@@ -1968,7 +1988,7 @@ static PHP_GINIT_FUNCTION(ps) /* {{{ */
        }
        ps_globals->http_session_vars = NULL;
 }
-/* }}}*/
+/* }}} */
 
 static PHP_MINIT_FUNCTION(session) /* {{{ */
 {
@@ -2048,7 +2068,7 @@ static PHP_MINFO_FUNCTION(session) /* {{{ */
 
        DISPLAY_INI_ENTRIES();
 }
-/* }}} */ 
+/* }}} */
 
 zend_module_entry session_module_entry = {
        STANDARD_MODULE_HEADER,
index 020723c8d3a2aa529ebc22c76d0820a53ac57d4f..29ceb3ef3eb86ba4c167fad3ac5dc9b0d166e763 100644 (file)
@@ -23,8 +23,8 @@ $_SESSION["foo"] = 1234567890;
 $_SESSION["bar"] = "Blah!";
 $_SESSION["guff"] = 123.456;
 var_dump($_SESSION);
-$encoded = "A2Zvb2k6MTIzNDU2Nzg5MDs=";
-var_dump(session_decode(base64_decode($encoded)));
+$encoded = "foo|i:1234567890;";
+var_dump(session_decode($encoded));
 var_dump($_SESSION);
 var_dump(session_destroy());
 
@@ -34,10 +34,11 @@ ob_end_flush();
 --EXPECTF--
 *** Testing session_decode() : variation ***
 
-Warning: session_start(): Unknown session.serialize_handler. Failed to decode session object in %s on line %d
-bool(true)
-array(0) {
-}
+Warning: session_start(): Cannot find serialization handler 'blah' - session startup failed in %s on line %d
+bool(false)
+
+Notice: Undefined variable: _SESSION in %s on line %d
+NULL
 array(3) {
   [u"foo"]=>
   int(1234567890)
@@ -49,14 +50,8 @@ array(3) {
 
 Warning: session_decode(): Unknown session.serialize_handler. Failed to decode session object in %s on line %d
 bool(true)
-array(3) {
-  [u"foo"]=>
-  int(1234567890)
-  [u"bar"]=>
-  unicode(5) "Blah!"
-  [u"guff"]=>
-  float(123.456)
-}
-bool(true)
-Done
+unicode(17) "foo|i:1234567890;"
 
+Warning: session_destroy(): Trying to destroy uninitialized session in %s on line %d
+bool(false)
+Done
index 3166041a1a427f637a9d52d2970a4bc3660384bb..db5a3685f50833fb2a08695683480d5ddc90d368 100644 (file)
@@ -31,4 +31,3 @@ bool(true)
 unicode(34) "foo|a:3:{i:0;i:1;i:1;i:2;i:2;i:3;}"
 bool(true)
 Done
-
index c2eb7d2ba252b668226664a6e2c46bd6ebce1257..a08b772ea288caa50e10ada153e7af1760090fe2 100644 (file)
@@ -33,4 +33,3 @@ bool(true)
 unicode(52) "foo|a:3:{i:0;i:1;i:1;i:2;i:2;i:3;}guff|R:1;blah|R:1;"
 bool(true)
 Done
-
index 4eefa8fcf50b2ec875d2adc90eeeb3af855c6822..136b64a7a563e78df269ac9cc59b764e055ae915 100644 (file)
@@ -33,4 +33,3 @@ bool(true)
 unicode(64) "data|a:5:{i:0;i:1;i:1;i:2;i:2;i:3;U:3:"foo";R:1;U:4:"blah";R:1;}"
 bool(true)
 Done
-
index 21f9974043bd4c2ea4a820d884d441e8b06dd938..0cac8af1afaec86243acebbb0f21128448a9cd7c 100644 (file)
@@ -32,4 +32,3 @@ bool(true)
 string(0) ""
 bool(true)
 Done
-
index 376c9ac1bf74b744e5e89f2d1aa1a0e207ff4d6c..033240aeae06904dfb710a264b31c4d860aad19e 100644 (file)
@@ -29,11 +29,12 @@ ob_end_flush();
 --EXPECTF--
 *** Testing session_encode() : variation ***
 
-Warning: session_start(): Unknown session.serialize_handler. Failed to decode session object in %s on line %d
-bool(true)
+Warning: session_start(): Cannot find serialization handler 'blah' - session startup failed in %s on line 13
+bool(false)
 
-Warning: session_encode(): Unknown session.serialize_handler. Failed to encode session object in %s on line %d
+Warning: session_encode(): Cannot encode non-existent session in %s on line 15
 string(0) ""
-bool(true)
-Done
 
+Warning: session_destroy(): Trying to destroy uninitialized session in %s on line 17
+bool(false)
+Done