zanyzonk1 Posted May 5, 2007 Share Posted May 5, 2007 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). Quote Link to comment https://forums.phpfreaks.com/topic/50169-simple-yet-clever-banning-script/ Share on other sites More sharing options...
MadTechie Posted May 5, 2007 Share Posted May 5, 2007 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; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/50169-simple-yet-clever-banning-script/#findComment-246345 Share on other sites More sharing options...
zanyzonk1 Posted May 5, 2007 Author Share Posted May 5, 2007 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; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/50169-simple-yet-clever-banning-script/#findComment-246361 Share on other sites More sharing options...
MadTechie Posted May 5, 2007 Share Posted May 5, 2007 Cool can you click solved please Quote Link to comment https://forums.phpfreaks.com/topic/50169-simple-yet-clever-banning-script/#findComment-246370 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.