...

View Full Version : Track down ip address on a database submission form?



crazykid
03-22-2010, 08:37 PM
Is there any way I can do a php or sql code where a person submits data into a database using a form and their ip address is also submitted? Some sites have this such as wikipedia where if a user submits information, their ip information is put into the database. Does anyone know the code?

masterofollies
03-22-2010, 08:46 PM
$ip=@$REMOTE_ADDR;
echo "<b>$ip</b>";

The above would display an IP like this 71.53.210.46

IP address if the register_global is off
If at php.ini if register_global is set to Off then we have to change the script a bit to get the address. Here it is


$ip=$_SERVER['REMOTE_ADDR'];

Then for your database query, just make a field for ipaddress and insert or update $ip

JAY6390
03-22-2010, 09:02 PM
Just to note you shouldn't have register globals on ever. It's very bad practice

masterofollies
03-22-2010, 10:54 PM
Correct, but just in case, I included both :thumbsup:

crazykid
03-23-2010, 11:42 PM
Out of curiosity...so the
$ip=$_SERVER['REMOTE_ADDR']; code captures the ip address?

What code do I use to inset the captures ip address into the database? This is what I got:


//Insert IP address to database
mysql_query("INSERT INTO quest (IPAddress) VALUES('$ip')") or die (mysql_error());

$quest_ipaddress=$_SERVER['IPAddress'];

DJCMBear
03-24-2010, 08:10 AM
A good coder would gather all the data needed before sending it to the database because I have seen your code and your inserting a few times into the same database table which will missmatch the data and insert more than 1 row at a time, once you validate all the submitted data and its all correct thats when you should insert the data into the database table. And your also asking a question you could easerly find or a SEO such as google.

pinkjerry2010
03-24-2010, 09:23 AM
A good coder would gather all the data needed before sending it to the database because I have seen your code and your inserting a few times into the same database table which will missmatch the data and insert more than 1 row at a time, once you validate all the submitted data and its all correct thats when you should insert the data into the database table. And your also asking a question you could easerly find or a SEO such as google.

One question I would like to follow up on is do you have to have 25 posts under your belt to purchase from a swap master?OR just to sell?
_____________________
Print koozies | (http://www.kustomkooziesonline.com/wiki.aspx/select_a_koozie_company.ascx)Koozie printing (http://www.kustomkooziesonline.com/wiki.aspx/select_a_koozie_company.ascx)

masterofollies
03-24-2010, 03:21 PM
Out of curiosity...so the
$ip=$_SERVER['REMOTE_ADDR']; code captures the ip address?

What code do I use to inset the captures ip address into the database? This is what I got:


//Insert IP address to database
mysql_query("INSERT INTO quest (IPAddress) VALUES('$ip')") or die (mysql_error());

$quest_ipaddress=$_SERVER['IPAddress'];

Basically yes this is correct.

Lin Lam
03-15-2011, 03:25 AM
Just to note you shouldn't have register globals on ever. It's very bad practice
Sorry, I am not a programmer. I'm developing a new company and I need a developer, so do you mind if I ask you why global is bad? Should I be telling a developer I don't want this? Thanks. I really appreciate it if you have time to reply. Lin



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum