作者:手机用户2702932415_836 | 来源:互联网 | 2023-09-14 19:52
代码如下define(COOKIES_PATH,);define(COOKIES_EXPIRES,gmstrftime(%A,%d-%b-%Y%H:%M:%SGMT,time(
代码如下
define('COOKIES_PATH', '/');
define('COOKIES_EXPIRES',gmstrftime("%A, %d-%b-%Y %H:%M:%S GMT",time()+9600));
header("Set-COOKIE:user[userid]=123;path =".COOKIES_PATH.";httpOnly;SameSite=Strict;expires=".COOKIES_EXPIRES.";",false);
header("Set-COOKIE:user[username]=123;path =".COOKIES_PATH.";httpOnly;SameSite=Strict;expires=".COOKIES_EXPIRES.";",false);
header("Set-COOKIE:user[password]=123;path =".COOKIES_PATH.";httpOnly;SameSite=Strict;expires=".COOKIES_EXPIRES.";",false);
header("Set-COOKIE:admin[username]='';path =".COOKIES_PATH.";expires=".gmdate('D, d M Y H:i:s GMT', time()-1).";",false);
header("Set-COOKIE:admin[password]='';path =".COOKIES_PATH.";expires=".gmdate('D, d M Y H:i:s GMT', time()-1).";",false);
可以通过设置httpOnly;和SameSite=Strict;对COOKIE进行禁止JS读取和禁止跨域读取.达到基础性的XSS和CSRF防护.