I have a php site. I want to store an last ip for each user. I want it to work for both IPV4 and IPV6 users. Any idea how?
Share
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.
Simply convert them to a binary representation using
inet_pton()and later back to a string usinginet_ntop().Another solution would be storing the IP string without any transformations in the DB. A
VARCHAR(39)field will do the job as the highest/longest IPv6 isffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff