The algo is very simple:
1) Visitor hits the .php file
2) The script determines if visitor's IP matches one of the IP ranges in a text file [url removed, login to view]
[url removed, login to view] is a list of IP ranges in CIDR format and it looks like this:
and so on.
3) If there is a match then visitor is redirected to URL1; if not then visitor is redirected to URL2