jaffy Posted October 29, 2006 Share Posted October 29, 2006 Hi,I am a complete newbie and have a ready made PHP script installed. However one thing it is missing is a way to capture the visitors IP address and storing it in the database when they register. I have found out how to get the visitors IP address with this;[code]<?php $ip = $_SERVER['REMOTE_ADDR']; echo "Your IP address is: $ip"; [/code]I have a redundant field on the register page which is used to enter a website, so I wish to simply use this field to automatically enter the visitors IP adressSo my question is, how do I get the $ip variable into the value field of an input field like this one;[code]<input type="text" name="IP Adress" value="{m_website}">[/code]Thanks for any help Quote Link to comment https://forums.phpfreaks.com/topic/25502-capturing-ip-and-placing-in-text-field/ Share on other sites More sharing options...
ignace Posted October 29, 2006 Share Posted October 29, 2006 [code]<input type="hidden" name="IP_Address" value="<?php echo $_SERVER['REMOTE_ADDR'];?>" />[/code]this is a hidden field, and is not being displayed to the user (unless they do view - source) so when he submit the form you will be able to "capture" his ip by using:[code]<?php# get the actual ip address by using the associative key created by the form (IP_Address)$ip = $_REQUEST['IP_Address'];# display ipecho $ip;?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/25502-capturing-ip-and-placing-in-text-field/#findComment-116349 Share on other sites More sharing options...
jaffy Posted October 29, 2006 Author Share Posted October 29, 2006 Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/25502-capturing-ip-and-placing-in-text-field/#findComment-116451 Share on other sites More sharing options...
Destruction Posted October 29, 2006 Share Posted October 29, 2006 The above method could be more easily 'spoofed' or neglected entirely. If you want to add it into the database, make sure of the database structure (ie: make sure you have a field for the IP address) and do something similar to this...[code]<?php$IP = $_SERVER['REMOTE_ADDR'];$Query = mysql_query("INSERT INTO `table` (`field`) VALUES ('$IP')");?>[/code]Obviously this will need to incorperate your current structure and be added to your registration database query that you already have.HTHDest Quote Link to comment https://forums.phpfreaks.com/topic/25502-capturing-ip-and-placing-in-text-field/#findComment-116454 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.