[英]PHP/MySQL: Prevent inserting according to several columns
When a user connects to a certain webpage I insert his IP address and the datetime of the connexion in MySQL. 当用户连接到某个网页时,我在MySQL中插入其IP地址和连接的日期时间。
For a reason I don't get, I often get 2 or 3 insertions for the same IP address at the exact same time. 出于某种原因,我经常在同一时间为同一IP地址插入2或3次插入。
Moreover, I don't want to add a new MySQL row if the user opens the webpage again within the 30 next minutes (I would consider this as the same visit from the user). 此外,如果用户在接下来的30分钟内再次打开网页,我也不想添加新的MySQL行(我认为这与用户的访问相同)。
Would it be possible to only insert a user IF his IP address hasn't been recorded at least for a range of half an hour? 如果至少在半小时内未记录用户的IP地址,是否可以只插入一个用户?
Here is the simple request I use: 这是我使用的简单请求:
INSERT INTO connex VALUES ('','".$ip."','".$datetime."')
And this is how it looks like in MySQL (id/ip/datetime): 这就是MySQL(id / ip / datetime)中的样子:
83 | 66.249.81.57 | 2014-08-11 23:52:21
84 | 66.249.81.57 | 2014-08-11 23:52:21
85 | 66.249.81.57 | 2014-08-11 23:52:21
Thank you. 谢谢。
Make a select statement like 做出如下选择语句
SELECT ip FROM connex WHERE ip = $ip AND datetime > DATE_SUB(NOW(), INTERVAL 30 MINUTE)
And check if you get a result for this request. 并检查您是否获得此请求的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.