Using PHP I’d like to compare an actual ip address to part of one, and see if it matches.
For example I want to see if the address matches 12.34..
<?php
$rem_address = getenv('REMOTE_ADDR');
$temp = substr ($rem_address,0,6)
if ($temp == "12.34.") echo "It's a match";
?>
Is there an easier/better way to do this?
The function strpos($haystack, $needle) will tell you the first position in the $haystack string where the substring appears.
As long as you are careful to check the with the === comparison operator, you can see if
"12.34"appears at the beginning of the IP address.Check out the documentation and pay careful attention to the Warning.