Jump to content

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;
  }
}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.