livewirerules Posted July 21, 2008 Share Posted July 21, 2008 Im coding a small rpg game script and i need to limit the users chances to play the game per ip. Eg: certain IP can play only 5 times a day Which means that the user can click on a certain link only 5 times. Im bit confused how to do this. Can someone please help me Quote Link to comment Share on other sites More sharing options...
craygo Posted July 21, 2008 Share Posted July 21, 2008 You will have to keep track of the visits either in some kind of text file of in a mysql database. but this will give you the ip address of the computer $ip = $_SERVER['REMOTE_ADDR']; then you will have to write the address to the preferred file or database Ray Quote Link to comment Share on other sites More sharing options...
marcus Posted July 21, 2008 Share Posted July 21, 2008 on the page with the clicking <?php $ip = $_SERVER['REMOTE_ADDR']; $sql = "SELECT * FROM `ip_log` WHERE `ip`='".$ip."'"; $res = mysql_query($sql) or die(mysql_error()); $err = false; if(mysql_num_rows($res) == 0){ $sql2 = "INSERT INTO `ip_log` (`ip`,`clicks`) VALUES('".$ip."','1')"; $res2 = mysql_query($sql2) or die(mysql_error()); $err = false; }else { $row = mysql_fetch_assoc($res); if($row['clicks'] >= 5){ $err = true; }else { $sql3 = "UPDATE `ip_log` SET `clicks`=`clicks`+1 WHERE `ip`='".$ip."'"; $res3 = mysql_query($sql3) or die(mysql_error()); $err = false; } } if($err){ echo "You have already clicked this page 5 times!"; }else { // whatever } ?> then i guess you can set a cron to run every 24 hours to reset em Quote Link to comment Share on other sites More sharing options...
natbob Posted July 21, 2008 Share Posted July 21, 2008 The simplest way is to use cookies, but it is very insecure, however if this is a low security situation it would do the job. <?php if (!isset($_COOKIE['plays'])) setcookie('plays', 0, time()+86400); else if ($_COOKIE['plays'] <= 5) { The code of the restricted page... $_COOKIE['plays']++; } else { echo "You are not allowed to play any more today, come back tomorrow."; } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.