Jump to content


Photo

Capturing IP and placing in text field


  • Please log in to reply
3 replies to this topic

#1 jaffy

jaffy
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 29 October 2006 - 05:32 PM

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;

<?php
 $ip = $_SERVER['REMOTE_ADDR']; 

echo "Your IP address is: $ip";

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 adress

So my question is, how do I get the $ip variable into the value field of an input field like this one;

<input type="text" name="IP Adress" value="{m_website}">

Thanks for any help

#2 ignace

ignace
  • Moderators
  • Now mod flavored
  • 6,430 posts
  • LocationBelgium

Posted 29 October 2006 - 05:55 PM

<input type="hidden" name="IP_Address" value="<?php echo $_SERVER['REMOTE_ADDR'];?>" />

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:

<?php
# get the actual ip address by using the associative key created by the form (IP_Address)
$ip = $_REQUEST['IP_Address'];

# display ip
echo $ip;
?>


#3 jaffy

jaffy
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 29 October 2006 - 08:36 PM

Thanks!

#4 Destruction

Destruction
  • Members
  • PipPipPip
  • Advanced Member
  • 108 posts

Posted 29 October 2006 - 08:46 PM

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...

<?php
$IP = $_SERVER['REMOTE_ADDR'];
$Query = mysql_query("INSERT INTO `table` (`field`) VALUES ('$IP')");
?>

Obviously this will need to incorperate your current structure and be added to your registration database query that you already have.

HTH

Dest




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users