Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different browsers, different IPs?

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)?

like image 704
federico-t Avatar asked Nov 15 '11 21:11

federico-t


People also ask

Do Different accounts have different IPs?

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.

Does IP address change with browser?

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 does Google show different IPs?

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.


3 Answers

  1. 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).

  2. Store the address in a string that's long enough to hold an IPv6 address.

  3. No, 'cause in the general case you cannot.

like image 117
Seva Alekseyev Avatar answered Oct 02 '22 01:10

Seva Alekseyev


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.

like image 44
knittl Avatar answered Oct 02 '22 00:10

knittl


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 :-)

like image 29
Sander Steffann Avatar answered Oct 02 '22 00:10

Sander Steffann