I'm saving the user's IP addresses by saving the value of $_SERVER['REMOTE_ADDR']
in a MySQL database. Problem is that for both Firefox and Chrome $_SERVER['REMOTE_ADDR']
is ::1
(that means localhost in IPv6) and for IE and Opera is 127.0.0.1
(IPv4).
So, my questions are
Are IP versions browser-dependant? (I used to think it depended on the computer)
Should I create two fields in the database, one for IPv4 addresses and one for IPv6 ones?
Should I unify all IPs to IPv6? And how can I do this in PHP (if it's even possible)?
IP addresses are global with Windows. In other words, every account uses the same IP address. You could, of course, use a logon script to set a specific IP address for a particular account.
HTTP/S proxies – Usually either browser extensions or special websites that work like a browser within your browser. They only change the IP address on data sent to and from your browser, but do not affect other apps or even DNS traffic.
Why in my computer command window is it showing a different IP address to Google's IP address? Because there are 2 different IP domains, your internal private home network, and the public network.
Fairly obvious - your box is IPv6-enabled, Firefox/Chrome use IPv6 whenever available, while IE and Opera don't (or it's a off-by-default setting).
Store the address in a string that's long enough to hold an IPv6 address.
No, 'cause in the general case you cannot.
Use the PHP function inet_pton
to convert human readable IP addresses to their packed representation. You can then store each IP address in a BINARY(16)
or VARBINARY(16)
field in your database.
The browser will use whatever is available. This can be IPv4 or IPv6, and that can even change during the session. On top of that keep in mind that a host can have many IPv6 addresses so it might change during the session as well.
In short: don't depend on the value of REMOTE_ADDR too much :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With