Simple login attempts monitor php script example Websites 2 Go Addon
Hi there!. I have added this simple login monitor to block excessive form posting by ip address.
This example as being a small script just writes ip and time to file with each post.
You can set the amount of attempts and the amount of time to block the user by hours.
Just include the script in your post to script and set redirect.
A simple login monitor can use session count as well. But is it easier to delete session or change your ip?
I would set this up along with a write ip to htacces to ban using substr to write a ip block to ban
along with sending me an email of the form abuse with the ip.
Click the submit button 3 times to test the script
But copy the script first or you will be blocked for 3 hours.
1: <?php
2: //free for personal use.
3: //copyright 2017 cmxads.com actionws
4: //credits intact
5: date_default_timezone_set('America/New_York');
6: if (isset($_SERVER["HTTP_CF_CONNECTING_IP"])) {
7: $_SERVER['REMOTE_ADDR'] = $_SERVER["HTTP_CF_CONNECTING_IP"];
8: }
9: $maxAttempts = 3;
10: //24hrs in min
11: //$timer1 = 86400;
12: //hours
13: $timer1 = 3600;
14: //muliplied by, to delete
15: $days1="3";
16: // Name of the file
17: $fname = "attempts.txt";
18: if(!file_exists($fname)){
19: touch($fname);
20: }
21: $areturn='';
22:
23: $ip1= (isset($_SERVER['REMOTE_ADDR']) && ($_SERVER['REMOTE_ADDR'] != "")) ? $_SERVER['REMOTE_ADDR'] : "Unknown";
24:
25: function char_rtrim($in){
26: if(strlen($in)>1){
27: return substr($in, 0, -1);
28: }}
29:
30: if(file_exists($fname) && filesize($fname)>0 && is_readable($fname)){
31: $datei1 = file($fname);
32: $timeout1 = time()-($days1*$timer1);
33:
34: for ($numm = 0; $numm < count($datei1); $numm++) {
35: $tiles1 = explode("|",$datei1[$numm]);
36: if ($tiles1[1] < $timeout1) {
37: unset($datei1[$numm]);
38: }
39: }
40: $filerep = implode("", $datei1);
41: $filerep = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $filerep);
42: file_put_contents($fname,$filerep,LOCK_EX);
43:
44: if($handle = @fopen($fname, 'r')){
45: if(flock($handle, LOCK_SH)){
46: if($areturn = file_get_contents($fname)){
47: flock($handle, LOCK_UN);
48: }}}fclose($handle);
49:
50: $checkip=char_rtrim($ip1);
51:
52: if($areturn and substr_count($areturn, $checkip)>=$maxAttempts){
53: echo "<p style=\"text-align:center;font-size:1.5em;color:red;\"><br><br>";
54: echo('Max attempts reached. Try again in '.$days1.'hrs or contact admin');
55: echo "<br><br></p>";
56: exit;
57: }
58: }
59: if (isset($_POST) && !empty($_POST)){
60: $t = time();
61: file_put_contents($fname, $ip1 . "|" . $t . "\n", LOCK_EX|FILE_APPEND);
62: }
63: ?>
Please help me I am handicapped and support myself
Donate With PayPal
Donate Bitcoin
Please donate and help the handicapped.
1Ev8n7R63yqkKsFTrztufvuVah44MCbzpNThanks!
name:Mark Date:11.26.21 @ 07:08am IP:01269.12231..
Thanks for sharing.
name:Abbie Date:10.24.21 @ 09:40am IP:107.175.82.111
Thanks your the greatest.
name:Abbie Date:09.29.21 @ 07:18am IP:62.210.139.12
I am using this worked out great I sent you 9 cents.
name:Tosha Date:09.29.21 @ 07:06am IP:62.210.139.12
I will give it a try. thanks.
name:Melaine Date:09.29.21 @ 00:51am IP:62.210.139.12
Thanks I love you I sent you 58 cents.
name:Gina Date:09.29.21 @ 00:42am IP:62.210.139.12
Thanks!
name:Freddy Date:09.4.21 @ 10:07am IP:62.210.178.249
I am using this worked out great I sent you 9 cents.
name:Judas Date:09.4.21 @ 09:58am IP:62.210.178.249
Thank you you are the best. Works like a charm. I sent you 22 cents.
name:Joe Date:03.26.21 @ 04:56am IP:109.234.37.227
Thanks I sent you 71 cents.
name:Kayleigh Date:01.31.21 @ 02:10am IP:62.210.207.209
Thanks for sharing.
name:Rachal Date:01.31.21 @ 01:49am IP:62.210.207.209
Thanks for sharing.
name:Rachal Date:08.20.19 @ 20:26pm IP:37.115.120.212
Thanks!
name:Precious Date:08.20.19 @ 20:06pm IP:37.115.120.212
Thanks I admire you I sent you 67 cents.
name:Jesus Date:10.14.17 @ 21:36pm IP:65.78.105.57
I found this very usefull thank you .