How to create a blocker with php codes?

Hello,
How to create a blocker with php codes? Any ip blocker that will help me track those ip of the people who accessed in my forum from the time date and ip addresses. There are some user who registers in my forum and leave stupid questions and write unpleasant comments. I would like to block them to avoid those people.
Waiting for your support, thank you.
