8000 feature #18102 Add IpUtils::isPrivateIp docs (danielburger1337) · symfony/symfony-docs@3022f02 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3022f02

Browse files
committed
feature #18102 Add IpUtils::isPrivateIp docs (danielburger1337)
This PR was squashed before being merged into the 6.3 branch. Discussion ---------- Add IpUtils::isPrivateIp docs References symfony/symfony#49726 Commits ------- 990596e Add IpUtils::isPrivateIp docs
2 parents 1fcba0b + 990596e commit 3022f02

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

components/http_foundation.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,23 @@ analysis purposes. Use the ``anonymize()`` method from the
361361
$anonymousIpv6 = IpUtils::anonymize($ipv6);
362362
// $anonymousIpv6 = '2a01:198:603:10::'
363363

364+
Check if an IP belongs to a private subnet
365+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
366+
367+
If you need to know if an IP address belongs to a private subnet, you can
368+
use the ``isPrivateIp()`` method from the
369+
:class:`Symfony\\Component\\HttpFoundation\\IpUtils` to do that::
370+
371+
use Symfony\Component\HttpFoundation\IpUtils;
372+
373+
$ipv4 = '192.168.1.1';
374+
$isPrivate = IpUtils::isPrivateIp($ipv4);
375+
// $isPrivate = true
376+
377+
$ipv6 = '2a01:198:603:10:396e:4789:8e99:890f';
378+
$isPrivate = IpUtils::isPrivateIp($ipv6);
379+
// $isPrivate = false
380+
364381
Accessing other Data
365382
~~~~~~~~~~~~~~~~~~~~
366383

0 commit comments

Comments
 (0)
0