0

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

Chris Forrence
  • 10,042
  • 11
  • 48
  • 64
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
  • 356,200
  • 43
  • 426
  • 500
3

You should read the following articles:

Community
  • 1
  • 1
Catalin MUNTEANU
  • 5,618
  • 2
  • 35
  • 43
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
  • 39,272
  • 12
  • 98
  • 118