FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

disallow users from visiting site twice in 15 minutes

 


janszmatt
How do i disallow registered members from visiting a site or using a function twice in 15 minutes or more?

i dont want cookies pls...
rohan2kool
to keep it short, all you need to do is save the timestamp whenever the user enters the page in a MySQL database. Let's say the coloumn in which it is saved is called 'last_time' and the coloumn in which the username is saved is 'username'. Then whenever the page is loaded, get the variable for the current user. Let's say the variable is $user. Get the corresponding value for last_time from the database:

SELECT last_time FROM mytable WHERE username = $user

You must be knowing the rest with mysql_fetch_array and all that, so won't go much into it. Let's suppose you get the last time in the variable as $last_time. All you need to check is whether the current timestamp is more than 15 minutes or not:

Code:

if(!((time() - $last_time) > 15*60)) {
   die("You cannot view the page twice in 15 minutes");
} else {
   //Show the page here
}


also remember that whenever you show the page, fill the data in the last_time entry with the corresponding username with the current time stamp.

hope it helps Very Happy
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.