How does PHP realize the limit of the number of times each mobile phone sends CAPTCHA per day?

I have connected to Ali Yun"s SMS message. How can I limit the number of times each phone receives CAPTCHA per day?

Mar.05,2021

SMS query API (QuerySendDetails)-PHP

check how many SMS messages have been accepted on the date corresponding to the change of mobile phone number


memcached/redis/ databases can do this

construct a key, based on the mobile phone number, such as Mobile number-send- Today

  1. read the value of this key before sending it. If it is greater than or equal to the set value, the API returns
  2. if it reports an error directly.
  3. send CAPTCHA
  4. set the value of the key + 1

is written in redis


it is recommended to use redis to record the logs sent every day, and count the number of times each mobile number sends verification per day. Do not send more times than the limit. Remember to clean this part of the log regularly.

of course you can do it using mysql, but redis is much faster.


use caching, redis as an example, before sending, for example, you want to limit the number of times you send per day,

  1. write a key as the mobile phone number. Date, value is the number of times, valid time is 24 hours, cache
  2. verify before sending a. Whether it exists (in line with the date of the day) b. Whether the number of times has reached the limit
  3. send in accordance with the conditions, and let the cache be self-incremented

if you want to be complicated, for example:

you can send it 5 times in 10 minutes, and wait 30 minutes for more than 5 times.

  1. write a cache with the mobile phone number as the key, the value as the number of times, the initial value as 1, and the cache for 10 minutes
  2. does the test exist, and if so, the number of times it is tested? If the number of times does not reach the maximum, the cache time will be changed to 30 minutes
  3. when it reaches the maximum number of times.

when registering, you can only send SMS verification code once per second. Logic

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e81a67-b74.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e81a67-b74.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?