简体   繁体   English

如何允许用户每天访问页面3次?(Php&Mysql)

[英]How to allow user to access a page 3 times per day?(Php & Mysql)

I am doing a responsive quiz for kids and I want to only allow them to do 3 times a day, after the third time they cannot access the page anymore. 我正在为孩子们做一个响应性的测验,我想只允许他们每天做三次,在他们第三次无法访问页面之后。

My responsive quiz currently has a log in and once they are logged in , the kids can choose the difficulty and after they chose the difficulty they can then proceed to do the questions. 我的响应测验目前有一个登录,一旦他们登录,孩子们可以选择难度,在他们选择难度后,他们可以继续做问题。

(As I am a beginner on php and mysql, how do I allow each user to be able to access the page only 3 times?) (由于我是php和mysql的初学者,如何让每个用户只能访问该页面3次?)

More secured way than cookies is to save information in database. 比cookie更安全的方式是将信息保存在数据库中。 There are many possible ways and maybe depends on programmer's imagination and creativity, but I would add two fields to database where i would store numbers and dates. 有很多可能的方法,可能取决于程序员的想象力和创造力,但我会在数据库中添加两个字段,我将存储数字和日期。 Each day your script should check current date and if equals to db date, than you check numbers. 每天你的脚本应检查当前日期,如果等于db日期,则检查数字。 If number is three, user should view disabled quiz buttons. 如果number为3,则用户应查看禁用的测验按钮。 If date's aren't equal and number is three, than you change it to 0 and each time quiz button is clicked you increment that by one. 如果日期不相等且数字为3,则将其更改为0并且每次单击测验按钮时,将其递增1。 That would be my solution and I don't think that it's perfect, but would work correctly 这将是我的解决方案,我不认为它是完美的,但会正常工作

The not-secure way to do this, Cookies. 这是一种不安全的方式,Cookies。 Each time the person opens a new page increment a cookie value and if it's 3 redirect to another page, (Not secure since people can just remove cookies) or using database queries, you can set some value in the database indicating time visited, and refresh this value each day. 每次打开一个新页面的人都会增加一个cookie值,如果它是3重定向到另一个页面,(不安全,因为人们可以删除cookie)或使用数据库查询,你可以在数据库中设置一些值,表明访问时间,并刷新每天这个价值。

When particular user login and try to access your page,at a time save entry in sql table for that user. 当特定用户登录并尝试访问您的页面时,一次在该用户的sql表中保存条目。 Now further user try to access same page then get details from that table and check whether field that specify number (how many time user enter), and if the field value is >3 then restrict user. 现在,进一步的用户尝试访问同一页面,然后从该表中获取详细信息,并检查是否指定了数字的字段(用户输入的时间),以及字段值是否> 3则限制用户。 I am not php person so I don't know how to restrict in php but you can redirect user to any page like error.php and write that you can attempt it more than 3 times. 我不是php人,所以我不知道如何在php中限制,但你可以将用户重定向到任何页面,如error.php,并写你可以尝试超过3次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM