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?
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.
Thanks!
You would just query where timestamp is greater than 24 hours ago.
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.
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?