File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -195,11 +195,15 @@ protected function getKeySuffix() : string
195195 * @param string $id The session id
196196 *
197197 * @see https://www.php.net/manual/en/sessionupdatetimestamphandlerinterface.validateid.php
198+ * @see https://wiki.php.net/rfc/deprecations_php_8_4#sessionsid_length_and_sessionsid_bits_per_character
198199 *
199200 * @return bool Returns TRUE if the id is valid, otherwise FALSE
200201 */
201202 public function validateId ($ id ) : bool
202203 {
204+ if (\PHP_VERSION_ID >= 80400 ) {
205+ return (bool ) \preg_match ('#\A[0-9a-f]{32}\z# ' , $ id );
206+ }
203207 $ bits = \ini_get ('session.sid_bits_per_character ' ) ?: 5 ;
204208 $ length = \ini_get ('session.sid_length ' ) ?: 40 ;
205209 $ bitsRegex = [
Original file line number Diff line number Diff line change @@ -82,8 +82,6 @@ protected function setOptions(array $custom) : void
8282 $ default = [
8383 'name ' => 'session_id ' ,
8484 'serialize_handler ' => $ serializer ,
85- 'sid_bits_per_character ' => 6 ,
86- 'sid_length ' => 48 ,
8785 'cookie_domain ' => '' ,
8886 'cookie_httponly ' => 1 ,
8987 'cookie_lifetime ' => 7200 ,
@@ -99,6 +97,10 @@ protected function setOptions(array $custom) : void
9997 'auto_regenerate_maxlifetime ' => 0 ,
10098 'auto_regenerate_destroy ' => true ,
10199 ];
100+ if (\PHP_VERSION_ID < 80400 ) {
101+ $ default ['sid_bits_per_character ' ] = 6 ;
102+ $ default ['sid_length ' ] = 48 ;
103+ }
102104 $ this ->options = $ custom
103105 ? \array_replace ($ default , $ custom )
104106 : $ default ;
Original file line number Diff line number Diff line change @@ -44,12 +44,31 @@ protected function replaceConfig(array $config) : void
4444 $ this ->config = \array_replace_recursive ($ this ->config , $ config );
4545 }
4646
47+ /**
48+ * @see https://wiki.php.net/rfc/deprecations_php_8_4#sessionsid_length_and_sessionsid_bits_per_character
49+ */
4750 public function testValidateId () : void
4851 {
52+ // Ids with PHP lower than 8.4:
4953 $ id6 = '62my7tSXcbIrOZ-WHsEXhpwUoG,afmBQNGaSBkFN ' ;
5054 $ id5 = 'iimuf8lvdectatt5jtkve15831funl8rg5cg6okp ' ;
5155 $ id4 = '96aa2c863140e0e714a603cf44b0afc9a0632592 ' ;
5256 $ this ->session ->stop ();
57+ /*
58+ * Since PHP 8.4 session.sid_bits_per_character and session.sid_length
59+ * are deprecated.
60+ *
61+ * - The default value for session.sid_bits_per_character is 4 (0-9, a-f).
62+ * - The default value for session.sid_length is 32 character.
63+ */
64+ if (\PHP_VERSION_ID >= 80400 ) {
65+ self ::assertFalse ($ this ->handler ->validateId ($ id6 ));
66+ self ::assertFalse ($ this ->handler ->validateId ($ id5 ));
67+ self ::assertFalse ($ this ->handler ->validateId ($ id4 ));
68+ $ idPhp84 = '96aa2c863140e0e714a603cf44b0afc9 ' ;
69+ self ::assertTrue ($ this ->handler ->validateId ($ idPhp84 ));
70+ return ;
71+ }
5372 \ini_set ('session.sid_bits_per_character ' , '6 ' );
5473 \ini_set ('session.sid_length ' , '40 ' );
5574 self ::assertTrue ($ this ->handler ->validateId ($ id6 ));
You can’t perform that action at this time.
0 commit comments