@SyCoJun 03.2009 — #This function from here claims to get the real IP address of a user.
[code=php]function getRealIpAddr() { if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet { $ip=$_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy { $ip=$_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip=$_SERVER['REMOTE_ADDR']; } return $ip; }[/code]
Once you have it you'll need to store it along with the time the ban starts in a SQL table. You then need a monitoring script that runs every minute. You can use a cronjob on Unix or a scheduled task on Windows so the job/task calls a script that looks in the table to see is any bans started more than 10 minutes ago and if so remove that record from the database.
The links provided should give you all the tutorials you need but post back f you need help with any of it.
If you'd like someone to write it for you this site can help.
@STREETRULEZJun 03.2009 — #a script wich bans an user for 10 minutes is commin' up
if your server don't know the $_SERVER['REMOTE_ADDR'] try the script from SyCo to get the IP address, but i don't think, that this var causes any trouble, cause APACHE and IIS are the most used web servers =)
and there we go:
first, we have to create the dbase-table:
it is not nessasery, witch engine you use, only the fields must exist:
4 mysql: [CODE] CREATE TABLE ipban.ipban ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY , ipaddress VARCHAR( 15 ) NOT NULL , timestamp TIMESTAMP NOT NULL , bantime TIMESTAMP NOT NULL , reason VARCHAR( 255 ) NOT NULL ) ENGINE = MYISAM [/CODE]
and the PHP-Code
(watch out for the first to lines in code and fit it to your server)
[code=php] <?PHP /** * STREETRULEZ **/
mysql_connect("localhost", "root", ""); // connect to a server mysql_select_db("ipban"); // select the database
ipban_banip($_SERVER['REMOTE_ADDR']); // this will ban the ipadress
/** * returns false, if ip is not banned * else returns the ip and reason for banning * suüpporting a die-mode XD **/ function ipban_checkip($ip, $die = false) { $res = mysql_query("select * from ipban where ipaddress = '". $ip ."' LIMIT 1;"); if(mysql_num_rows($res) < 1) return false; $r = mysql_fetch_array($res, MYSQL_ASSOC); if($die) die($r['ipaddress'] ." is banned because ". $r['reason']); else return $r['ipaddress'] ." is banned because ". $r['reason']; }
/** * add ip vor time secs with the reason * to the bantable **/ function ipban_banip($ip, $time = 600, $reason = "you are banned!") { $btime = time() + $time; $btime = date("Y-m-d H:i:s", $btime); mysql_query("insert into ipban (ipaddress, timestamp, bantime, reason) values ('". $ip ."', NOW(), '". $btime ."', '". $reason ."')") or die(mysql_error()); return true; } ?> [/code]
finished XD
this is simple code =)
i've wrote that down in 10 minutes using notepad++ and XAMP from apachefriends.org XD
have phun with it - if it causes troubles feel free to query me some questions by pm or mail [email][email protected][/email]
sorry, bout bad english - i'm from austria and my mothers tounge is german -.-
@SyCoJun 03.2009 — #You'll still need a monitoring script that unbans the ip after 10 mins. The snippet I posted is to get the real ip if it's behind a proxy. Some ISPs put all their customers behind a handful of IPs so by banning the ip of the proxy you ban hundreds or thousands of people.