Skip to content

Commit 6715f1d

Browse files
committed
Merge branch '6.4' into 7.1
* 6.4: docs(http-foundation): check if ip is in cidr subnet
2 parents d043474 + 6e14857 commit 6715f1d

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

components/http_foundation.rst

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

365+
Check If an IP Belongs to a CIDR Subnet
366+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
367+
368+
If you need to know if an IP address is included in a CIDR subnet, you can use
369+
the ``checkIp()`` method from :class:`Symfony\\Component\\HttpFoundation\\IpUtils`::
370+
371+
use Symfony\Component\HttpFoundation\IpUtils;
372+
373+
$ipv4 = '192.168.1.56';
374+
$CIDRv4 = '192.168.1.0/16';
375+
$isIpInCIDRv4 = IpUtils::checkIp($ipv4, $CIDRv4);
376+
// $isIpInCIDRv4 = true
377+
378+
$ipv6 = '2001:db8:abcd:1234::1';
379+
$CIDRv6 = '2001:db8:abcd::/48';
380+
$isIpInCIDRv6 = IpUtils::checkIp($ipv6, $CIDRv6);
381+
// $isIpInCIDRv6 = true
382+
365383
Check if an IP Belongs to a Private Subnet
366384
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
367385

0 commit comments

Comments
 (0)