MySQL Storage IP address operation

Source: Internet
Author: User
Tags administrator password yii

Database data table creation syntax:

DROP TABLE IF EXISTS' admin ';CREATE TABLE IF  not EXISTS' admin ' (' Adminid ' )INTUNSIGNED not NULLAuto_increment COMMENT'primary Key ID', ' Adminuser 'VARCHAR( +) not NULL DEFAULT "'COMMENT'Administrator Account', ' AdminPass 'CHAR( +) not NULL DEFAULT "'COMMENT'Administrator Password', ' AdminEmail 'VARCHAR( -) not NULL DEFAULT "'COMMENT'Admin e-mail', ' logintime '      bigint  UNSIGNED not  null  default  Span style= "COLOR: #ff0000" > " 0  "  COMMENT  "  logon time   " , ' Loginip '  bigint  not  null  default   " 0   " COMMENT  "  logon IP   "   , ' Createtime 'INTUNSIGNED not NULL DEFAULT '0'COMMENT'creation Time',    PRIMARY KEY(' Adminid '),UNIQUEadmin_adminuser_adminpass (' Adminuser ', ' AdminPass '),UNIQUEadmin_adminuser_adminemail (' Adminuser ', ' AdminEmail ')) ENGINE=InnoDBDEFAULTCHARSET=UTF8;

(1) Under MySQL console:

IP address-to-integer type :Inet_aton

mysql> updateset userip=Inet_aton ('192.168.1.1' where username='admin';
Mysql> Select *  fromadmin;+---------+-----------+----------------------------------+----------------+------------+------------+--------- ---+|Adminid|Adminuser|AdminPass|AdminEmail|Logintime|Loginip|Createtime|+---------+-----------+----------------------------------+----------------+------------+------------+--------- ---+|       1 |Admin|202cb962ac59075b964b07152d234b70|Zq@zqblogs. cn| 1482500788 |3232235777| 1482419387 |+---------+-----------+----------------------------------+----------------+------------+------------+--------- ---+1Rowinch Set(0.00Sec

int-Turn IP address type :inet_ntoa

mysql> Select inet_ntoa (4294967295);
+ -- ---------------------+ | Inet_ntoa (4294967295| + -- ---------------------+ | 255.255. 255.255       | + -- ---------------------+

(2) PHP code implementation: Ip2long

Inserting an IP address into a field with a data type of int or bigint via PHP code ( syntax using the YII framework )

$this->updateall (
Time Ip2long (Yii::$app

$this->adminuser]
);
Yii:: $app->request->userip: Indicates the IP address obtained through the HTTP request header to the current user's browser (note: Available through $_server[' remote_addr ') Get to local IP address)
(Illustration 1: Use 127.0.0.1 to access the local Apache server instead of the Localhost,localhost IP:: 1, bigint type that does not conform to the database limit)
(Note 2: The IP address and domain name mappings for the Web server are configured in the C:\Windows\System32\drivers\etc\hosts file

Description: Reprint Please specify the source http://www.cnblogs.com/zqblogc/p/6216237.html

Friendship Reference: http://www.qttc.net/201208193.html

MySQL Storage IP address operation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.