Skip to content

Instantly share code, notes, and snippets.

@morontt
Created October 3, 2024 20:58
Show Gist options
  • Save morontt/2af7fe71c2d48cdccb4d98e96a8f469e to your computer and use it in GitHub Desktop.
Save morontt/2af7fe71c2d48cdccb4d98e96a8f469e to your computer and use it in GitHub Desktop.
/**
* examples:
* 10.10.85.13/32
* 10.10.85.13/24
*/
[$subnet, $mask] = explode('/', $cidr);
return (ip2long($clientIP) & ~((1 << (32 - $mask)) - 1)) == ip2long($subnet);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment