Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you get a users IP and store it?

Status
Not open for further replies.

meeble3

Programmer
Nov 8, 2004
52
GB
Hello,

I want to get a users IP address and store it in the MySQL database along with a couple of other normal fields.

How do I do this? How do I account for proxy servers sending 'UNKNOWN'?

What is the best type to store an IP address as?

Regards,

James
 
Assuming it is an IPv4 address, you could store it as a BIGINT if you converted it to a decimal form first, however, it would probably be easier to use if you store it as a string, leaving it in dotted-decimal (normal) notation. (Further info on IPv4 formats available here:
As for getting the information, it will usually be stored in the REMOTE_ADDR field, and some proxy servers will also send the IP of their client and that may be stored in a variable as well. However, the information provided by proxy servers can vary quite a bit, if it exists at all, you may find this page helpful:
HTH
Gavin
 
If a user is behind a proxy server that does not report the user's address or if the user is on a network that is using NAT and private addresses, there's not much you can do to get the user's actual address. That is, after all, the whole point of NAT and proxy servers.


It's difficult to say what is the best method for storing your IP addresses. That answer will depend a lot on what you intend to do with them once they're in the database.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top