Skip to content

Commit 5c06111

Browse files
committed
Documented the IPUtils::anonymize method
1 parent 0ad9a9f commit 5c06111

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

components/http_foundation.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,28 @@ are also supported::
316316
$quality = $accept->get('text/xml')->getQuality(); // $quality = 0.8
317317
$quality = $accept->get('application/xml')->getQuality(); // $quality = 0.3
318318

319+
Anonymizing IP Addresses
320+
~~~~~~~~~~~~~~~~~~~~~~~~
321+
322+
.. versionadded:: 4.4
323+
324+
The ``anonymize()`` method was introduced in Symfony 4.4.
325+
326+
An increasingly common need for applications to comply with user protection
327+
regulations is to anonymize IP addresses before logging and storing them for
328+
analysis purposes. Use the ``anonymize()`` method from the
329+
:class:`Symfony\\Component\\HttpFoundation\\IpUtils` to do that::
330+
331+
use Symfony\Component\HttpFoundation\IpUtils;
332+
333+
$ipv4 = '123.234.235.236';
334+
$anonymousIpv4 = IPUtils::anonymize($ipv4);
335+
// $anonymousIpv4 = '123.234.235.0'
336+
337+
$ipv6 = '2a01:198:603:10:396e:4789:8e99:890f';
338+
$anonymousIpv6 = IPUtils::anonymize($ipv6);
339+
// $anonymousIpv6 = '2a01:198:603:10::'
340+
319341
Accessing other Data
320342
~~~~~~~~~~~~~~~~~~~~
321343

0 commit comments

Comments
 (0)