L.e.e. 发表于 2013-5-30 15:13:59

关于 inet_aton() 函数

CI里 有没有 类似inet_aton() 函数?

$this->input->ip_address() 获取IP地址 用 SQL函数 inet_aton() 格式化后 存到数据库~

                                $data = array(
                                        'ip' => inet_aton($this->input->ip_address()),
                                );
                                $this->db->insert('Top.note_posts', $data);

我想 达到 这个效果 该怎么写 或者CI里有没有 IP地址 格式化的函数?

Hex 发表于 2013-5-30 16:39:54

是要把字符串的 xxx.xxx.xxx.xxx 转成整数形式吧?
用 PHP 自带的函数 ip2long()
具体查一下 PHP 手册。

L.e.e. 发表于 2013-5-30 21:41:14

Hex 发表于 2013-5-30 16:39 static/image/common/back.gif
是要把字符串的 xxx.xxx.xxx.xxx 转成整数形式吧?
用 PHP 自带的函数 ip2long()
具体查一下 PHP 手册。 ...

知道啦 谢谢 哈~

dickfu 发表于 2013-5-31 12:15:43

本帖最后由 dickfu 于 2013-5-31 12:17 编辑

ip2long在32位机器上有bug,128.0.0.0/1 的ip地址会转换不对,因为第一位用来存符号了,实际只支持31位,为了保证正确性这么用吧
bindec(decbin(ip2long($ip)));

L.e.e. 发表于 2013-5-31 13:19:18

dickfu 发表于 2013-5-31 12:15 static/image/common/back.gif
ip2long在32位机器上有bug,128.0.0.0/1 的ip地址会转换不对,因为第一位用来存符号了,实际只支持31位,为了保 ...

啊~~谢谢哈~

L.e.e. 发表于 2013-6-4 15:31:10

dickfu 发表于 2013-5-31 12:15 static/image/common/back.gif
ip2long在32位机器上有bug,128.0.0.0/1 的ip地址会转换不对,因为第一位用来存符号了,实际只支持31位,为了保 ...

那我要 取出来的时候 应该 用什么函数啊?

L.e.e. 发表于 2013-6-4 17:37:51

L.e.e. 发表于 2013-6-4 15:31 static/image/common/back.gif
那我要 取出来的时候 应该 用什么函数啊?

原来用 long2ip() 可以把整数转IP 呵呵 解决了~
页: [1]
查看完整版本: 关于 inet_aton() 函数