本文介绍了如何设置cookie为20分钟,并检查他们是否过期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在想一个系统,允许用户每20分钟只发布一篇文章。我不使用成员系统,所以我想我可以设置一个cookie为20分钟。并且当用户发布的东西检查是否设置cookie如果是显示消息像只有一个帖子每20分钟允许如果它不设置为数据库中的东西。

I was thinking of a system that will allow users to post only 1 article per 20 min. I don't use a member system so I thought I could set a cookie for 20 min. And when user posts something check if cookie is set if yes show message like "Only 1 post per 20 min allowed" if it is not set than put stuff in database.

我对php相对较新,不知道如何设置cookie,我试图查看关于cookies的php.net手册,但它对我来说太混乱了。所以,你可以展示如何设置一个安全的cookie为20分钟,并检查它是否或未设置。

I'm relatively new to php and don't know how to set cookies, I tried looking at php.net manual on cookies, but it was too confusing for me. So can you please show how to set a secure cookie for 20 min and check if it is or is not set. Maybe you have Better suggestions that will work instead of cookies etc.

谢谢。

推荐答案

查看这些函数:




  • setCookie
  • get cookie value

要将Cookie设置为20分钟,您可以执行以下操作:

To set a cookie for 20 min you can do this:

setcookie("postedArticle", true, time() + (60 * 20)); // 60 seconds ( 1 minute) * 20 = 20 minutes

检查是否设置了cookie: p>

Check if cookie is set:

if(isset($_COOKIE['postedArticle']) && $_COOKIE['postedArticle'] == true)
{ 
    // IS SET and has a true value
}    

这篇关于如何设置cookie为20分钟,并检查他们是否过期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 06:45