我读到在数据库中存储IP地址的最佳方法是创建一个Unsigned Int(10)字段.如何使用PHP转换IP地址?我试过用了
$this->ip = long2ip($_SERVER['REMOTE_ADDR']);
Run Code Online (Sandbox Code Playgroud)
但这似乎不起作用.我找到了使用它将其转换回IP地址的方法
$this->ip = sprintf("%u", ip2long($result['ip']));
Run Code Online (Sandbox Code Playgroud)
我最初如何转换IP地址?我应该使用PHP吗?或者更好地集成到MySQL查询中?