@@ -42,8 +42,12 @@ public function register(){
4242 unset($ ret ['password ' ]);
4343 session ("login_user " , $ ret );
4444 $ token = D ("UserToken " )->createToken ($ ret ['uid ' ]);
45- cookie ('cookie_token ' ,$ token ,array ('expire ' =>60 *60 *24 *90 ,'httponly ' =>'httponly ' ));//此处由服务端控制token是否过期,所以cookies过期时间设置多久都无所谓
46- $ this ->sendResult (array (
45+ if (version_compare (PHP_VERSION ,'7.3.0 ' ,'> ' )){
46+ setcookie ('cookie_token ' ,$ token ,array ('expires ' =>time ()+60 *60 *24 *180 ,'httponly ' =>'httponly ' ,'samesite ' => 'Strict ' ,'path ' =>'/ ' ));
47+ }else {
48+ cookie ('cookie_token ' ,$ token ,array ('expire ' =>60 *60 *24 *180 ,'httponly ' =>'httponly ' ));
49+ }
50+ $ this ->sendResult (array (
4751 "uid " => $ ret ['uid ' ] ,
4852 "username " => $ ret ['username ' ] ,
4953 "name " => $ ret ['name ' ] ,
@@ -134,7 +138,11 @@ public function login(){
134138 session ("login_user " , $ ret );
135139 D ("User " )->setLastTime ($ ret ['uid ' ]);
136140 $ token = D ("UserToken " )->createToken ($ ret ['uid ' ],60 *60 *24 *180 );
137- cookie ('cookie_token ' ,$ token ,array ('expire ' =>60 *60 *24 *180 ,'httponly ' =>'httponly ' ));//此处由服务端控制token是否过期,所以cookies过期时间设置多久都无所谓
141+ if (version_compare (PHP_VERSION ,'7.3.0 ' ,'> ' )){
142+ setcookie ('cookie_token ' ,$ token ,array ('expires ' =>time ()+60 *60 *24 *180 ,'httponly ' =>'httponly ' ,'samesite ' => 'Strict ' ,'path ' =>'/ ' ));
143+ }else {
144+ cookie ('cookie_token ' ,$ token ,array ('expire ' =>60 *60 *24 *180 ,'httponly ' =>'httponly ' ));
145+ }
138146 $ this ->sendResult (array (
139147 "uid " => $ ret ['uid ' ] ,
140148 "username " => $ ret ['username ' ] ,
@@ -247,8 +255,11 @@ public function registerByVerify(){
247255 unset($ ret ['password ' ]);
248256 session ("login_user " , $ ret );
249257 $ token = D ("UserToken " )->createToken ($ ret ['uid ' ]);
250- cookie ('cookie_token ' ,$ token ,array ('expire ' =>60 *60 *24 *90 ,'httponly ' =>'httponly ' ));//此处由服务端控制token是否过期,所以cookies过期时间设置多久都无所谓
251-
258+ if (version_compare (PHP_VERSION ,'7.3.0 ' ,'> ' )){
259+ setcookie ('cookie_token ' ,$ token ,array ('expires ' =>time ()+60 *60 *24 *180 ,'httponly ' =>'httponly ' ,'samesite ' => 'Strict ' ,'path ' =>'/ ' ));
260+ }else {
261+ cookie ('cookie_token ' ,$ token ,array ('expire ' =>60 *60 *24 *180 ,'httponly ' =>'httponly ' ));
262+ }
252263 $ this ->sendResult (array (
253264 "uid " => $ ret ['uid ' ] ,
254265 "username " => $ ret ['username ' ] ,
0 commit comments