Jump to content

Recommended Posts

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 adress

So 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
Link to comment
https://forums.phpfreaks.com/topic/25502-capturing-ip-and-placing-in-text-field/
Share on other sites

[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 ip
echo $ip;
?>
[/code]
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.

HTH

Dest
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.