cookie 设置报错 setcookie() expects parameter 3 to be integer, float given in...

使用 setcookie 函数设置 cookie 报错,报错信息为:

setcookie() expects parameter 3 to be integer, float given in...

错误代码

setcookie("user_name", $username, time()+3153600000, "/"); 

一开始以为是 https 的问题,后来修改为 http only 也不行,最后发现原来是设置 cookie 过期的时间戳太大,从报错信息看也是显示第三个参数错误,

试着把时间戳调小一点..居然没报错了,看来确实是时间戳的问题。
突然想起,时间戳的最大值是到 2038年 (32位),一查,果然超了。
再看看配置文件,写的是66 * 265 * 86400,居然是66年过期,已经超过了PHP的setcookie函数处理范围
把配置调小,错误立马解决

猜你喜欢

转载自www.cnblogs.com/ryanzheng/p/11980217.html