Or even better, if you're running Unix/Linux;
Use host.allow to block server wide access to IPs of your choice.
The paranoid, you can even set up a firewall to block certain IPs.
But if you really want PHP to do it, I support UrlGuy's example of using REMOTE_ADDR and array to store them.
Also be sure to google for HTTP_X_FORWARDED_FOR, which is a variable that lists the real IP address of users from proxies.
I'm not 100% on how the host system works, but from what i've seen, tons of people have the same host (with a different IP based prefix)... so banning a host could cause some undesierable effects. Also IP banning isn't exactly great because of the above stated reason.