Jump to content

Simple yet clever Banning Script


zanyzonk1

Recommended Posts

I have a website I am working on for a friend. Per his request, I have setup a quiz which visitors must pass in order to access the site. If they pass, it sends them to a web address which allows registration.

 

Here's the problem - He wants a script which will ban the I.P addresses of people that fail the quiz. I have so far though of a way to do this. It forwards them to a banning page:

 

This will be a php page which picks up their I.P address and adds it to an .htaccess file in the form of:

 

'deny from 123.123.1.123' (the 123... etc being their I.P). And adds each ban on a seperate line. That's all it is. However, I lack the skills in php to do this.

 

If anyone could help, it would be greatly appreciated (I won't be able to hug and kiss you, but you can pretend if you like lol).

Link to comment
https://forums.phpfreaks.com/topic/50169-simple-yet-clever-banning-script/
Share on other sites

Quick append script (UNTESTED)

 

someone may post a better one or theirs the freelance section

 

either why it may help

 

<?php
addtofile(".htaccess","line to add");

function addtofile($n,$d) {
  $f=@fopen($n,"a");
  if (!$f) {
    return false;
  } else {
    fwrite($f,$d);
    fclose($f);
    return true;
  }
}
?>

Well, I modified it and finally got it working all okay.

 

Just CHMOD .htaccess 0777

 

Create a php page in the same directory as your .htaccess file, or change the path of .htaccess in the code.

 

The page will consist of this code:

 

<?php

$ip = $_SERVER['REMOTE_ADDR'];

echo "You're Banned";

addtofile(".htaccess","deny from $ip
");

function addtofile($n,$d) {
  $f=@fopen($n,"a");
  if (!$f) {
    return false;
  } else {
    fwrite($f,$d);
    fclose($f);
    return true;
  }
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.