Skip to content

Commit 6e14857

Browse files
committed
Merge branch '5.4' into 6.4
* 5.4: Minor tweaks docs(http-foundation): check if ip is in cidr subnet
2 parents 7f421ea + 248138d commit 6e14857

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
@@ -375,6 +375,24 @@ analysis purposes. Use the ``anonymize()`` method from the
375375
$anonymousIpv6 = IpUtils::anonymize($ipv6);
376376
// $anonymousIpv6 = '2a01:198:603:10::'
377377

378+
Check If an IP Belongs to a CIDR Subnet
379+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
380+
381+
If you need to know if an IP address is included in a CIDR subnet, you can use
382+
the ``checkIp()`` method from :class:`Symfony\\Component\\HttpFoundation\\IpUtils`::
383+
384+
use Symfony\Component\HttpFoundation\IpUtils;
385+
386+
$ipv4 = '192.168.1.56';
387+
$CIDRv4 = '192.168.1.0/16';
388+
$isIpInCIDRv4 = IpUtils::checkIp($ipv4, $CIDRv4);
389+
// $isIpInCIDRv4 = true
390+
391+
$ipv6 = '2001:db8:abcd:1234::1';
392+
$CIDRv6 = '2001:db8:abcd::/48';
393+
$isIpInCIDRv6 = IpUtils::checkIp($ipv6, $CIDRv6);
394+
// $isIpInCIDRv6 = true
395+
378396
Check if an IP Belongs to a Private Subnet
379397
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
380398

0 commit comments

Comments
 (0)