If we have an ip address as below:
127.0.0.1
Does both functions convert the ip address to the same number, or do they differ and have different result?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
They are almost exactly the same. ip2long sometimes returns a negative value because PHP uses signed numbers for valuation, while MySQL uses unsigned.
Both are evaluated as
x*(2^24) + y*(2^16) + z*(2^8) + w*(2^0), but in PHP, due to the long being signed, will show negative values for certain IP addresses.So, addresses while translate to over +2,147,483,647 will wrap around and give negative values.
This link describes this in detail.