How do I fetch the IP address of a user, then store it into a MySQL table?
3 Answers
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.

- 356,200
- 43
- 426
- 500
You should read the following articles:
How to get the real IP address using PHP: http://roshanbh.com.np/2007/12/getting-real-ip-address-in-php.html
How to store the IP address in MySQL: Max length for client ip address

- 1
- 1

- 5,618
- 2
- 35
- 43
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