PowWeb Forums - The Perfect Community for the Perfect Host  

Register now to interact with over 11,000 members! Registered users have Posting Privileges, free access to Private Messaging, Email Notifications and more.

Go Back   PowWeb Community Forums > The PowWeb Platform > PHP
User Name
Register FAQ Members List Search Today's Posts Mark Forums Read

Closed Thread
Thread Tools
Old 7-31-08, 02:19 PM   #1
Join Date: Feb 2002
Posts: 365
Reputation: 27
Capture IP in Registration Form

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

Last edited by notset4life; 7-31-08 at 02:31 PM.. Reason: Figured it out - somewhat
notset4life is offline  
Old 7-31-08, 05:12 PM   #2
Join Date: Jun 2006
Location: Houston, TX USA
Posts: 33
Reputation: 22
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.
genericnumber1 is offline  
Old 7-31-08, 05:26 PM   #3
Join Date: Feb 2002
Posts: 365
Reputation: 27
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 is offline  
Old 7-31-08, 05:40 PM   #4
Join Date: Feb 2002
Posts: 365
Reputation: 27
actually, a stupid question - I can figure out the variable. thanks again
notset4life is offline  
Closed Thread

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

All times are GMT -4. The time now is 11:08 PM.

Contents ©PowWeb, Inc. ~ vBulletin, Copyright 2000-2007 Jelsoft Enterprises Limited.