@@ -802,6 +802,7 @@ PHP_INI_BEGIN()
802802 STD_PHP_INI_ENTRY ("session.cookie_domain" , "" , PHP_INI_ALL , OnUpdateSessionString , cookie_domain , php_ps_globals , ps_globals )
803803 STD_PHP_INI_ENTRY ("session.cookie_secure" , "0" , PHP_INI_ALL , OnUpdateSessionBool , cookie_secure , php_ps_globals , ps_globals )
804804 STD_PHP_INI_ENTRY ("session.cookie_httponly" , "0" , PHP_INI_ALL , OnUpdateSessionBool , cookie_httponly , php_ps_globals , ps_globals )
805+ STD_PHP_INI_ENTRY ("session.cookie_samesite" , "" , PHP_INI_ALL , OnUpdateString , cookie_samesite , php_ps_globals , ps_globals )
805806 STD_PHP_INI_ENTRY ("session.use_cookies" , "1" , PHP_INI_ALL , OnUpdateSessionBool , use_cookies , php_ps_globals , ps_globals )
806807 STD_PHP_INI_ENTRY ("session.use_only_cookies" , "1" , PHP_INI_ALL , OnUpdateSessionBool , use_only_cookies , php_ps_globals , ps_globals )
807808 STD_PHP_INI_ENTRY ("session.use_strict_mode" , "0" , PHP_INI_ALL , OnUpdateSessionBool , use_strict_mode , php_ps_globals , ps_globals )
@@ -1360,6 +1361,11 @@ static int php_session_send_cookie(void) /* {{{ */
13601361 smart_str_appends (& ncookie , COOKIE_HTTPONLY );
13611362 }
13621363
1364+ if (PS (cookie_samesite )[0 ]) {
1365+ smart_str_appends (& ncookie , COOKIE_SAMESITE );
1366+ smart_str_appends (& ncookie , PS (cookie_samesite ));
1367+ }
1368+
13631369 smart_str_0 (& ncookie );
13641370
13651371 php_session_remove_cookie (); /* remove already sent session ID cookie */
@@ -1658,18 +1664,18 @@ PHPAPI void session_adapt_url(const char *url, size_t urllen, char **new, size_t
16581664 * Userspace exported functions *
16591665 ******************************** */
16601666
1661- /* {{{ proto bool session_set_cookie_params(int lifetime [, string path [, string domain [, bool secure[, bool httponly]]]])
1667+ /* {{{ proto void session_set_cookie_params(int lifetime [, string path [, string domain [, bool secure[, bool httponly[, string samesite] ]]]])
16621668 Set session cookie parameters */
16631669static PHP_FUNCTION (session_set_cookie_params )
16641670{
16651671 zval * lifetime ;
1666- zend_string * path = NULL , * domain = NULL ;
1672+ zend_string * path = NULL , * domain = NULL , * samesite = NULL ;
16671673 int argc = ZEND_NUM_ARGS ();
16681674 zend_bool secure = 0 , httponly = 0 ;
16691675 zend_string * ini_name ;
16701676
16711677 if (!PS (use_cookies ) ||
1672- zend_parse_parameters (argc , "z|SSbb " , & lifetime , & path , & domain , & secure , & httponly ) == FAILURE ) {
1678+ zend_parse_parameters (argc , "z|SSbbS " , & lifetime , & path , & domain , & secure , & httponly , & samesite ) == FAILURE ) {
16731679 return ;
16741680 }
16751681
@@ -1727,6 +1733,12 @@ static PHP_FUNCTION(session_set_cookie_params)
17271733 zend_string_release_ex (ini_name , 0 );
17281734 }
17291735
1736+ if (argc > 5 ) {
1737+ ini_name = zend_string_init ("session.cookie_samesite" , sizeof ("session.cookie_samesite" ) - 1 , 0 );
1738+ zend_alter_ini_entry (ini_name , samesite , PHP_INI_USER , PHP_INI_STAGE_RUNTIME );
1739+ zend_string_release (ini_name );
1740+ }
1741+
17301742 RETURN_TRUE ;
17311743}
17321744/* }}} */
@@ -1746,6 +1758,7 @@ static PHP_FUNCTION(session_get_cookie_params)
17461758 add_assoc_string (return_value , "domain" , PS (cookie_domain ));
17471759 add_assoc_bool (return_value , "secure" , PS (cookie_secure ));
17481760 add_assoc_bool (return_value , "httponly" , PS (cookie_httponly ));
1761+ add_assoc_string (return_value , "samesite" , PS (cookie_samesite ));
17491762}
17501763/* }}} */
17511764
@@ -2630,6 +2643,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_session_set_cookie_params, 0, 0, 1)
26302643 ZEND_ARG_INFO (0 , domain )
26312644 ZEND_ARG_INFO (0 , secure )
26322645 ZEND_ARG_INFO (0 , httponly )
2646+ ZEND_ARG_INFO (0 , samesite )
26332647ZEND_END_ARG_INFO ()
26342648
26352649ZEND_BEGIN_ARG_INFO (arginfo_session_class_open , 0 )
0 commit comments