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

Appearance settings

Commit 990596e

Browse filesBrowse files
danielburger1337OskarStark
authored andcommitted
Add IpUtils::isPrivateIp docs
1 parent 1fcba0b commit 990596e
Copy full SHA for 990596e

File tree

1 file changed

+17
-0
lines changed
Filter options

1 file changed

+17
-0
lines changed

‎components/http_foundation.rst

Copy file name to clipboardExpand all lines: components/http_foundation.rst
+17Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.