Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit990596e

Browse files
danielburger1337OskarStark
authored andcommitted
Add IpUtils::isPrivateIp docs
1 parent1fcba0b commit990596e

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)

[8]ページ先頭

©2009-2025 Movatter.jp