PDA

View Full Version : Restricting..



Sunny.
25-08-2009, 05:55 PM
How would I restrict a IP from using my uploader for more than 6 times. Im going to use L?ke's multi login script.

I only need a fairly simple strict to restrict an ip from using it more 6 times a day.

L?KE
25-08-2009, 07:17 PM
Have a database that stores IP, visits and date.

Then on the page have something like this:



<?php

/* connection details here */

$ip = $_SERVER['REMOTE_ADDR'];
$today = date("d m Y");

$sql = mysql_num_rows(mysql_query("SELECT * FROM `yourtable` WHERE `ip`='".$ip."' AND `date`='".$today."';"));

if($sql==0) //they have not visited today
{

$create = mysql_query("INSERT INTO `yourtable` ( `ip`, `date`, `visits` ) VALUES ( '".$ip."', '".$today."', '1');");
// show uploader

}
elseif($sql==1) //they have visited today
{

$count = mysql_fetch_array(mysql_query("SELECT * FROM `yourtable` WHERE `date`='".$today."' AND `ip`='".$ip."';"));

if($count['visits']==6)
{

// tell them to **** off

}
else
{

$new = $count['visits']++;
$update = mysql_query("UPDATE `yourtable` SET `visits`='".$new."' WHERE `ip`='".$ip."';");
// show uploader

}


}




give that a bash, may not work

Sunny.
25-08-2009, 08:10 PM
Didnt work. Thanks for the post though

L?KE
28-08-2009, 06:25 PM
Well what exactly went wrong with it? I can't refine it otherwise.

Heinous
29-08-2009, 07:25 AM
Limiting it to six uses is pretty stupid.

Say they need 10 uses. Either upload 60% to yours, then the remainder to another, or just use something like tinypic?

Gg.

Dentafrice
29-08-2009, 03:36 PM
This should work..


<?php
$ip = $_SERVER["REMOTE_ADDR"];
$time = time();

$query = mysql_query("SELECT * FROM `ips` WHERE `ip`='$ip' LIMIT 0,1");
$check = mysql_num_rows($query);

if($check) {
// user is in the database.
$data = mysql_fetch_object($query);

if($data->count == 6 && ($time - $data->time) <= 86400) {
exit("You have used your limit.");
}

}

// upload code

if($check) {

if(($time - $data->time) > 86400) {
$count = 1;
} else {
$count = ($data->count + 1);
}

mysql_query("UPDATE `ips` SET `count`='$count', `time`='$time' WHERE `ip`='$ip'");
} else {
// need to insert, not update.
mysql_query("INSERT INTO `ips` (ip, time) VALUES('$ip', '$time')");
}

Want to hide these adverts? Register an account for free!