Click here to Skip to main content
15,889,992 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I need a way to convert a users IP into a partial IP IE if the users IP is "78.64.34.142" it'll convert it to "78.64."
Posted

1 solution

Step 1. To get the client's ip, read this:
get-client-ip-address-using-php[^]
Step 2. To get the partial ip from a valid ip in php, see example code:
PHP
// $clientIP contains the client ip obtained from Step 1
$ipPart=explode('.', $clientIP);

if (count($ipPart) == 4)
{
    $partialIP = $ipPart[0].'.'.$ipPart[1];
}
else {
    $partialIP = 'UNKNOWN';
}
echo $partialIP;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900