Skip to content

Commit

Permalink
Fix #1, add a static method to anonymize addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
geertw committed Jun 24, 2017
1 parent 98c8ffa commit 2270042
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions example.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,10 @@

var_dump($ipAnonymizer->anonymize('2610:28:3090:3001:dead:beef:cafe:fed3'));
// returns 2610:28:3090:3001::

// You can use this class also in a static way:
var_dump(IpAnonymizer::anonymizeIp('192.168.178.123'));
// returns 192.168.178.0

var_dump(IpAnonymizer::anonymizeIp('2610:28:3090:3001:dead:beef:cafe:fed3'));
// returns 2610:28:3090:3001::
12 changes: 12 additions & 0 deletions src/IpAnonymizer.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace geertw\IpAnonymizer;

class IpAnonymizer {
Expand All @@ -12,6 +13,17 @@ class IpAnonymizer {
*/
public $ipv6NetMask = "ffff:ffff:ffff:ffff:0000:0000:0000:0000";

/**
* Anonymize an IPv4 or IPv6 address.
*
* @param $address string IP address that must be anonymized
* @return string The anonymized IP address. Returns an empty string when the IP address is invalid.
*/
public static function anonymizeIp($address) {
$anonymizer = new IpAnonymizer();
return $anonymizer->anonymize($address);
}

/**
* Anonymize an IPv4 or IPv6 address.
*
Expand Down

0 comments on commit 2270042

Please sign in to comment.