PDA

View Full Version : Capture IP in Registration Form


notset4life
7-31-08, 01:19 PM
I am trying to capture a user's IP and add it to a database from a PHP web page registration form.
I added this to the form:

<input type="hidden" name="ip_address" value="<? $ip = getenv("REMOTE_ADDR"); print $ip; ?>">

The "value" actually shows the IP address on the page when used elsewhere, so I assumed the hidden form here would pick it up.
After submission, I insert $ip_address into database - but it comes up EMPTY. No data is added to my IP field.
------------------------------------------------------------------------------------------------------------------------------------------------------

UPDATE: I just figured it out. In MYSQL database, I had VARCHAR as the field TYPE. I changed it to INT, but that produces a 5 digit number.
I need it to format in the database as the full ip address, - So to settle this, what is the best field TYPE to use for an IP address? - INT,Text,Double?

thanks again

genericnumber1
7-31-08, 04:12 PM
I've always just used varchar.. it should work fine as long as you don't put too small of a length limit on it.

Also, it's more secure to get the ip address as a variable and add it directly on the page that processes the form. If you try to pass it through a form, someone could easily change it to whatever they want.

notset4life
7-31-08, 04:26 PM
thanks for the help. Right now, it's a "hidden form" field, but I see you can easily see that in the source code.

If you don't mind, how do you "add the variable"?

notset4life
7-31-08, 04:40 PM
actually, a stupid question - I can figure out the variable. thanks again