How does the behavior of ip2long vary across different PHP versions and operating systems?

The behavior of ip2long can vary across different PHP versions and operating systems due to differences in how they handle IPv4 addresses. To ensure consistent behavior, it is recommended to use the PHP function inet_pton to convert the IPv4 address to binary format before using ip2long.

function custom_ip2long($ip) {
    $packed_ip = inet_pton($ip);
    if ($packed_ip === false) {
        return false; // Invalid IP address
    }
    $unpacked_ip = unpack('N', $packed_ip);
    if ($unpacked_ip === false) {
        return false; // Error unpacking IP address
    }
    return $unpacked_ip[1];
}

// Example usage
$ip = '192.168.1.1';
$long_ip = custom_ip2long($ip);
echo $long_ip;