The "ip_address()" Drupal Function

If you are a Drupal module developer, then the title of this Quicktip might be enough for a lightbulb to suddenly appear above your head.

This tip is one of those where you might say to yourself, "I didn't know there was a Drupal function for that!" The ip_address() function simply returns a reverse proxy adjusted value for the user's IP address. Until I found this function I was using PHP's $_SERVER['REMOTE_ADDR'] variable to capture the user's IP address.

A quick search of Drupal's code (and of some commonly used modules) indicates that this is the preferred way to capture this information, as modules such as comment, poll, webform, and votingapi all utilize this function.

Sign up to receive email notifications of whenever we publish a new blog post or quicktip!