hi i have a script that prevents banned ips from viewing the index file or anyfile that includes script i will paste below

help adding a banned ip into ips.txt file

to use include check_ip.php listed below

PHP Code:
if (
in_array($_SERVER['REMOTE_ADDR'], $banned)){
<body style="background:#000000">
<body bgcolor="#000000" text="#FFFFFF" link="#0000FF"> 
<font color="orange" font size="+4">
<img src="/images/logojnet.png" width="65" height="48" alt="logo" title="J~Net"  style="padding:15px;"></a> 
<br> You Are Banned!<p> To Check Again <p> Click <a href="/">Here!</a><p><br> <p> Or To Leave<p><br> Click <a href="http://www.google.com">Here!</a>'

I am asking, how to 1. detect if someone should be banned based on a attempted ddos attack (maybe using (excess amount of ping data within a set amount of short time),

and second, how to then add that ip (from user that is attempting to do a ddos attack), into ips.txt file, both files are on the root of the web server on linux apache 2. if you can help with 1 or more parts of this please reply.