# Is it enough to make unsigned to record the IP in integer?

Translate ip addresses of users in method int ip2long

In the logs of the error
``Numeric value out of range: 1264 Out of range value for column 'ip' at row 1``

Because the converted value ip more than can be int

`\$table->integer('ip')->unsigned()->nullable();`

This is enough for proper recording of data obtained from ip2long ip? Or bigint to do?
March 20th 20 at 11:49
March 20th 20 at 11:51
Solution
Perhaps the error is related to ipv6 address
I use this
``````/**
* Convert an IP address from presentation to decimal(39,0) format suitable for storage in MySQL
*
* @param string \$ip_address An IP address in IPv4, IPv6 or decimal notation
* @return string The IP address in decimal notation
*/
{
}

if (strpos(\$ip_address, ':') !== false) {
\$parts = unpack('N*', \$network);

foreach (\$parts as &\$part) {
if (\$part < 0) {
}

if (!is_string(\$part)) {
\$part = (string) \$part;
}
}

\$decimal = \$parts[4];

return \$decimal;
}

}

/**
* Convert an IP address from decimal format to presentation format
*
* @param string \$decimal An IP address in IPv4, IPv6 or decimal notation
* @return The string IP address in presentation format
*/
inet_dtop function(\$decimal)
{
// The IPv4 or IPv6 format
if (strpos(\$decimal, ':') !== false || strpos(\$decimal, '.') !== false) {
return \$decimal;
}

// Decimal format
\$parts = array();
\$parts[1] = bcdiv(\$decimal, '79228162514264337593543950336', 0);
\$decimal = bcsub(\$decimal, bcmul(\$parts[1], '79228162514264337593543950336'));
\$parts[2] = bcdiv(\$decimal, '18446744073709551616', 0);
\$decimal = bcsub(\$decimal, bcmul(\$parts[2], '18446744073709551616'));
\$parts[3] = bcdiv(\$decimal, '4294967296', 0);
\$decimal = bcsub(\$decimal, bcmul(\$parts[3], '4294967296'));
\$parts[4] = \$decimal;

foreach (\$parts as &\$part) {
if (bccomp(\$part, '2147483647') == 1) {
\$part = bcsub(\$part, '4294967296');
}

\$part = (int) \$part;
}

\$network = pack('N4', \$parts[1], \$parts[2], \$parts[3], \$parts[4]);