Basic PHP Programming For IP Address Filters and Blacklists

Amongst the many PHP traffic tracking and analysis methods, one of the more useful is the ability to separate users by IP Address and perform PHP actions on certain addresses. You might want to treat IP Addresses separately, and on your PHP Program can do this. Whether you are tracking page hits by IP Address, creating a custom experience for each user, or generating a blacklist to limit site access, the core essential is separating site connections by IP Address.

There are two IP Addresses you can collect from each user connection. There is an external (global) IP Address and an internal (local) IP Address. The local address is not always populated, depending on the network configuration of the user’s environment. If the user is operating behind a router, the browser may reside on a computer that has been issued a temporary internal IP Address. The router may or may not have a permanent address. Routers are another discussion, but suffice it here to understand that a router typically generates IP Addresses that are only valid in intranets, not on the Internet, such as and, etc.

When the user makes a request to the web server for content, the web server is privy to a block of connection information including the IP Addresses, operating system specifications, browser type and flavor, and other great information. Bear in mind that much of this information can be forged by qualified hackers. Some traffic may also arrive through both legitimate and illegitimate proxies, so geopositioning IP Address Translation will not be 100% accurate. We therefore are working with the majority of addresses, not all.

Now your PHP Web Application needs to handle situations when the offending IP Address is discovered. You can store the list of IP Addresses in various places. They may be sored into a MySQL Database, into flat files on the server file system, or somewhere else. The PHP Program can do a lookup for the IP Address in a database to see if there is a match, oriterate the list as an array looking for match. Once a match has been made, the PHP Program can perform additional operations ranging from counter tracking on the IP Address to displaying custom content to sending remote messages to someone.

Leave a Reply