简体   繁体   中英

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?)

More secured way than cookies is to save information in database. 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. If number is three, user should view disabled quiz buttons. 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. 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. 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.

When particular user login and try to access your page,at a time save entry in sql table for that user. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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