如何限制用户每天在PHP中多次登录 [英] How to restrict user to login more than once a day in php

查看:107
本文介绍了如何限制用户每天在PHP中多次登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以限制用户每天登录一次.这在PHP中可行吗?如果可以的话,您可以指导我怎么做吗?

Is there a way to restrict users not to login more that once per day. Is this possible in PHP? if so can you guide me in how to do it?

在我的数据库中,我有用户名和密码字段以及时间戳?我应该添加什么?

In my database i have username and password fields and timestamp? What should I add more?

我尝试了此操作,但问题是我不希望它受 IP 限制,应该尊重用户.

I tried this but the problem is that i don't want it to restrict with IP and should be respect to user.

<?php
mysql_connect("localhost", "root", "");
mysql_select_db("");

mysql_query("delete from restrict where time >= " . time() + (24*3600));

$result = mysql_query("select * from restrict where ip =\"{$_SERVER['REMOTE_ADDR'}\"");

if(mysql_num_rows($result) == 0) {
$sql = "insert into restrict values('', '{$_SERVER['REMOTE_ADDR']}', '" . time() . "')";
mysql_query($sql);
} else {
die("You cannot access this page for 24hrs after you viewed it last...");
}

mysql_close();
?> 

在此方面的任何帮助将不胜感激.

Any help on this will be appreciated.

谢谢!

推荐答案

您只需查询时间戳大于24小时的地方.

You would just query where timestamp is greater than 24 hours ago.

$sql = "SELECT COUNT(1) FROM `users` WHERE `timestamp` >= DATE_SUB(NOW(), INTERVAL 1 DAY)";

如果有结果,请不要让它们进入.

If there is a result, don't let them in.

这假设您有一个用户表,其中的时间戳记字段在用户登录时会更新.我不知道您对帖子中的整个限制表在做什么.

This assumes you have a user table with a timestamp field that is updated when a user logs in. I don't know what you're doing with this whole restrict table in your post.

这是一个有缺陷的系统.您应该存储一个cookie或其他东西,以防万一出了什么问题而导致它们注销,发生了什么事情,等等,然后再对您所提供的服务进行处理.当然,在不知道您真正要做什么的情况下我会知道些什么?

This is a flawed system though. You should be storing a cookie or something in case something goes wrong and they get logged out, something happens, etc, before they are done with whatever you are serving. Course, what do I know without knowing what you're really up to here?

这篇关于如何限制用户每天在PHP中多次登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆