向现有(或不存在)数组添加键
我得到了这段代码:
if( empty ($cache[$id]) ) {
$arr[$id] = @TIMENOW;
setcookie('id', cArr($arr, 'set'), -1, @PATH);
} else {
$cache[$id] = @TIMENOW;
setcookie('id', cArr($cache, 'set'), -1, @PATH);
}
它只向 cookie 添加一个键,如果我转到另一个线程,它会重置数组,并且不会添加更多键。我的意思是,如果用户转到 id
1 的线程,则 if(empty ($cache[1]) )
会添加 1,而是会更新现有值,并且如果用户现在转到 ID 为 5 的线程,它将执行相同的操作,并且 if(empty ($cache[5]) )
为空,然后它将添加密钥数组的 ID 为 5,这样我就拥有两个密钥现在:1 和 5。
希望你明白了。如果您不这样做,请随时提出您想要的任何问题,我会回答您的所有问题。
I got this code:
if( empty ($cache[$id]) ) {
$arr[$id] = @TIMENOW;
setcookie('id', cArr($arr, 'set'), -1, @PATH);
} else {
$cache[$id] = @TIMENOW;
setcookie('id', cArr($cache, 'set'), -1, @PATH);
}
And it is adding only one key, to the cookie
, if I'll go to the another thread , it'll reset the array, and won't add more keys. I mean, if the user goes to the thread with id
1 then if( empty ($cache[1]) )
is adding 1, instead it'll update existing value, AND if user will go now to the thread with ID 5, it will do the same, and if( empty ($cache[5]) )
is empty , then it'll add the key with ID 5 to the array so I'll have both keys now: 1 and 5.
Hope you got it. If you don't , feel free to ask for whatever you wan't, I'll reply for all of your quesitons.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
了解您在
cArr()
中所做的事情会很有帮助。但如果没有它,这将为用户访问的每个新线程添加到您的 cookie 中。警告:但请记住,只要设置 cookie,您的网络服务器就可能被利用。因此,最好不要使用
serialize
和unserialize
在 cookie 中存储简单的静态值。It would be helpful to know what you're doing in
cArr()
. But without it, this will add to your cookie for each new thread a user visits.WARNING: But keep in mind, that with just setting a cookie, your webserver can be exploited. So better not use
searialize
andunserialize
to store simple static values inside your cookie.