0
用下面的PHP/SQL ...PHP的Windows 7的IPv6變通IP列不能爲空
function ip2long6($ip)
{//ipv6 to ipv4 (string) to get Windows 7 local working
// Temp work-around until we convert the string to support ipv6 natively in SQL.
if (substr_count($ip, '::')) {$ip = str_replace('::', str_repeat(':0000', 8 - substr_count($ip,':')).':',$ip);}
$ip = explode(':',$ip);
$r_ip = '';
foreach ($ip as $v) {$r_ip .= str_pad(base_convert($v,16,2),16,0,STR_PAD_LEFT);}
return base_convert($r_ip,2,10);
}
$ip = mysql_real_escape_string($_SERVER['REMOTE_ADDR']);
$ip = mysql_real_escape_string(ip2long6($ip));
INSERT INTO log (ip) VALUES (INET_ATON('1208321'))
我得到以下錯誤...
列 'IP'不能爲空
我們現在怎樣才能獲得$ ip IPv4兼容?
一個工作的答案...
if (is_int($ip)) {$ipsql = mysql_real_escape_string("INET_ATON('$ip')");}
else {$ipsql = mysql_real_escape_string($ip);}
有了這個,我只是回答INET_ATON('$ip')
與$ipsql
。
一個疏忽,謝謝...現在在尋找它... – John