ip2long,32-bit/64-bit

It is a common practice,to use ip2long() function for getting integer-representation of ip-address (for database-storage).

Problem:

on systems with 32-bit integers,ip2long() returns values from -2147483648 to 2147483647

on systems with 64-bit integers,ip2long() returns values from 0 to 42949672945

Which means,that if you were using INT as a storage type on 32-bit server,you will need to change that field to be UNSIGNED INT (or BIGINT) on 64-bit server.

There is no simple migration,sorry.

p.s. similiar problems can appear in other intger-related functions too

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • DZone
  • FriendFeed
  • Reddit
  • Tumblr
  • Twitter
Liked this post? Follow me on twitter:@jimi_dini.

  • http://www.alexatnet.com/ Alex Netkachov

    Actually,it is clearly shown in doc for ip2long that “you need to use the “%u”formatter of sprintf() or printf() to get the string representation of the unsigned IP address.”

  • http://indeyets.pp.ru/ indeyets

    I know. But signed long was just fine for me. I understand why it has changed.

    The problem is:people tend to think about PHP as about high-level language (and hope,that it will take care of such interoperability issues).
    But such examples show,that many parts of it are still low-levelish

  • http://www.heureka.cz krteQ

    I always use built-in Mysql function INET_ATON() and have no problems :) Of course,the point is i never use other DB than Mysql

  • jeteir

    Which means,in fact,that PHP SHOULD deal with it by itself.

    It’s not a pretty thing for language that supports:// wrappers to halt on this.

A sample text widget

Etiam pulvinar consectetur dolor sed malesuada. Ut convallis euismod dolor nec pretium. Nunc ut tristique massa.

Nam sodales mi vitae dolor ullamcorper et vulputate enim accumsan. Morbi orci magna,tincidunt vitae molestie nec,molestie at mi. Nulla nulla lorem,suscipit in posuere in,interdum non magna.