PHP Classes

File: php_and_mysql.txt

Recommend this page to a friend!
  Classes of Bas Jobsen   Storeip   php_and_mysql.txt   Download  
File: php_and_mysql.txt
Role: Documentation
Content type: text/plain
Description: IMPORTANT
Class: Storeip
Store ip-addresses in a database
Author: By
Last change:
Date: 21 years ago
Size: 1,537 bytes
 

Contents

Class file image Download
After posting this class at phpclasses.org I got serveral emails about mysql default function to do to same (in a better way (?)) and the same for PHP. For MYSQL>=2.23: Use field properties for IPs ip int unsigned NOT NULL default '0' Use MySQL functions- from int to ip, and from ip to int INET_ATON INET_NTOA INET_NTOA(expr) Given a numeric network address (4 or 8 byte), returns the dotted-quad representation of the address as a string: mysql> SELECT INET_NTOA(3520061480); -> "209.207.224.40" INET_ATON(expr) Given the dotted-quad representation of a network address as a string, returns an integer that represents the numeric value of the address. Addresses may be 4 or 8 byte addresses: mysql> SELECT INET_ATON("209.207.224.40"); -> 3520061480 The generated number is always in network byte order; for example the above number is calculated as 209*256^3 + 207*256^2 + 224*256 +40. see: http://www.mysql.com/doc/en/Miscellaneous_functions.html Thanks to: AzDG <support@azdg.com> Michael Brunson <michael@mbweb.com> -- FOR PHP>=4.0 You shouldn't even use this class!! Use ip2long() and long2ip() insteads see: http://www.php.net/manual/en/function.ip2long.php http://www.php.net/manual/en/function.long2ip.php Note: Because PHP's integer type is signed, and many IP addresses will result in negative integers, you need to use the "%u" formatter of sprintf() or printf() to get the string representation of the unsigned IP address. Thanks to: Alexei Saveliev <lexa@netcera.com> --