1 (edited by Inquisitus 2006-07-15 03:19)

Topic: IP address database format

Not so much a feature request as a suggestion smile

I was looking through the database structure of PunBB and noticed that IP addresses are stored in VARCHAR fields as strings.  It would be more efficient (disc-space size-wise) to store them as unsigned 32-bit integers in decimal format, which would use only 4 bytes, rather than 15.  This can be done quite easily with the following two functions:

function encode_ip($ip_string)
{
    $ip_hex = '';
    $octets = explode($ip_string, '.');
    foreach ($octets as $octet)
    {
        $ip_hex .= dechex($octet);
    }
    return hexdec($ip_hex);
}

function decode_ip($ip_int)
{
    $ip_hex = dechex($ip_int);
    $octets = array();
    for ($i = 0; $i < strlen($ip_hex); $i += 2)
    {
        $octets[] = hexdec(substr($ip_hex, $i, 2));
    }
    return implode('.', $octets);
}

Just thought this would be a neater and smaller way of recording IP addresses smile

Another thing; I noticed that the migration tool doesn't carry IP addresses over from phpBB to PunBB.  phpBB actually uses a similar system for storing IP addresses, only it stores them as hexadecimal strings (e.g. 255.255.255.255 is stored as FFFFFFFF) in VARCHAR fields.  It would therefore be pretty easy to adapt the migrator to convert these IP addresses.

edit: Sorry, my bad... seems the migrator carries the post IP addresses over, and the registration IPs aren't recorded in phpBB hmm