Download & Extend

IP Address Field (D7 Fields)

This provides a field for storing an IP address or range.

The shorthand widget allows a user to enter the values in any of the following formats:

  • example.com
  • 10.10.10.10
  • 10.10.10.*
  • 10.10.10.0 - 10.10.12.255
  • 10.10.10.10-20

The CIDR widget allows CIDR inputs only:

  • 10.10.10.10/32

The addresses are stored internally as a long, this allows you to do network computations quickly (e.g. is 10.10.10.10 within the range 10.10.10.0 - 10.10.10.50).

This code will find any user entities that have an IP range which includes the visitors current IP address.

<?php
$visitor_addr
= ip2long($user->hostname);
$query = new EntityFieldQuery();
$result = $query
   
->entityCondition('entity_type', 'user')
    ->
propertyCondition('status', 1)
    ->
fieldCondition('field_yourfieldname', 'start', $visitor_addr, '<=', 0)
    ->
fieldCondition('field_yourfieldname', 'end', $visitor_addr, '>=', 0)
    ->
execute();
?>

Downloads

Recommended releases

Version Downloads Date Links
7.x-1.0-beta1 tar.gz (10.28 KB) | zip (11.34 KB) 2012-Mar-06 Notes

Development releases

Version Downloads Date Links
7.x-1.x-dev tar.gz (10.28 KB) | zip (11.34 KB) 2012-Mar-07 Notes

Project Information


Maintainers for IP Address Field (D7 Fields)

  • aidanlis - 12 commits
    last: 11 weeks ago, first: 32 weeks ago

Issues for IP Address Field (D7 Fields)

To avoid duplicates, please search before submitting a new issue.
All issues
Bug reports
nobody click here