in reply to REMOTE_ADDR not working

REMOTE_ADDR breaks when there is a proxy involved. A better way is to first check for X-FORWARDED-FOR in the HTTP headers using $q->http('X-FORWARDED-FOR'). Proxies should set this field. Take note that there may be several comma-separated entries in that field. If that field is not set, get the IP from REMOTE_ADDR.