0

How do I fetch the IP address of a user, then store it into a MySQL table?

Chris Forrence
  • 9,860
  • 11
  • 47
  • 62
Sam K.
  • 147
  • 6

3 Answers3

4

Your title says implies one question, and the question text is another. PHP stores the IP of the user as $_SERVER['REMOTE_ADDR']. You can stuff that into MySQL directly as a string, or convert it to an integer, in which case you'd have to consider someone coming in via IPv6 and having a 128bit IP address, not just 32bit.

Marc B
  • 348,685
  • 41
  • 398
  • 480
3

You should read the following articles:

Community
  • 1
  • 1
Catalin MUNTEANU
  • 5,558
  • 2
  • 33
  • 42
1

As you can see on https://stackoverflow.com/questions/1437771/how-can-i-get-the-clients-ip-address-in-a-php-webservice, getting an IP in PHP is done by accessing the $_SERVER['REMOTE_ADDR'] variable.

To store an IP in MySQL easily, you can either

  • use a CHAR(15)
  • use the INET_ATON(expr) function
Community
  • 1
  • 1
Konerak
  • 38,301
  • 12
  • 96
  • 116