I've been trying to get the visitor IP address (and host if possible) put into a hidden field to submit with a contact form.

The site is hosted on godaddy so the submission form is gdform.php. I haven't had much luck tinkering with their php file, so I'd rather place this in the html form I guess. (But willing to try anything.

The field for IP will be named/id'd as "ip", the field for host is "host"

here is the php for godaddy's gdform.php

<?php
	$request_method = $_SERVER["REQUEST_METHOD"];
	if($request_method == "GET")
	{
		$query_vars = $_GET;
	} 
	elseif ($request_method == "POST")
	{
		$query_vars = $_POST;
	}

	reset($query_vars);
	$t = date("U");
	$file = $_SERVER['DOCUMENT_ROOT'] . "\ssfm\gdform_" . $t;
	$fp = fopen($file,"w");

	while (list ($key, $val) = each ($query_vars)) 
	{
		fputs($fp,"<GDFORM_VARIABLE NAME=$key START>\r\n"); 
		fputs($fp,"$val\r\n");
		fputs($fp,"<GDFORM_VARIABLE NAME=$key END>\r\n");
		if ($key == "redirect") 
		{ 
			$landing_page = $val;
		}
	}

	fclose($fp);
	
	if ($landing_page != "")
	{
		header("Location: http://".$_SERVER["HTTP_HOST"]."/$landing_page");
	} 
	else 
	{
		header("Location: http://".$_SERVER["HTTP_HOST"]."/");
	}
?>

You should not have this information. Spamming is the only reason anyone wants it.

The IP address is usually useless anyway. Most ISPs, hosts, and routers now generate one-time IP addresses, to prevent spamming. Each time someone logs in, they get a new one.

You don't need it.

I am not a spammer, don't sell anything via the internet/email (except a handful of ebay items/year) and I use IP addys often.

My contact form is for people to contact my our small underfunded $2,000/ annual budget? and ask for assistance. Before we spend significant time resources researching their issue, we'd like to know if they are from the East Coast like they say, or really from Nigeria.

Since every email contains an IP address, getting one from the contact form is not unreasonable.

You should not have this information. Spamming is the only reason anyone wants it.

The IP address is usually useless anyway. Most ISPs, hosts, and routers now generate one-time IP addresses, to prevent spamming. Each time someone logs in, they get a new one.

You don't need it.

most godaddy hosting includes php
the php $_server[] array used in the godaddy form already includes this information
its a matter of changing your html form to a php form (by changing the file extension)
and coding something like

<input type='hidden' id='ip' name='ip' value='<?php echo $_server["remote_address"]; ?>'>
<input type='hidden' id='host' name='host' value='<?php echo $_server["remote_host"]; ?>'>

Very few IP address change except those on dialup.
the ISP has to retain the information for billing and liability protection,
the more often they alter the ip,
the more data they have to retain
mine usually alters every 6 months
the ip data and all page access data is retained in the server logs, this is no ideal world, everything is logged
:attachment: server log image

Almostbob - Thanks for the reply

Yes, my godaddy hosting includes php and the form is being submitted using php - a standard form created by gd.

I have created html documents for almost 9 years, but just have attempted using php. (I did create a php submittal file for a form created on a different server.)

The code you gave me makes perfect sense, but I can't get it to work.

I've tried taking my whole html and making it a text php file - I get all kinds of parsing errors, I'm sure my html is not coded in an up-to-date fashion. I use KompoZer to create.

I've tried creating a file

Almostbob - Thanks for the reply. Yes, my godaddy hosting includes php and the form is being submitted using php - a standard form created by gd.

I have created html documents for almost 9 years, but just have attempted using php. (I did create a php submittal file for a form created on a different server - didn't inlcude IPs.)

The code you gave me makes perfect sense, but I can't get it to work.
Here is what I've tried:
- I've tried taking my whole html and making it a text php file - I get all kinds of parsing errors, I'm sure my html is not coded in an up-to-date fashion. I use KompoZer to create my html.

- I've tried creating a php file "contactform.php" with just the code you gave me, then including this within my html form:

<?php
              
<input id="ip" name="ip" size='25' value='<?php echo $_server["remote_address"]; ?>' type='text'>
<input id="host" name="host" value='<?php echo $_server["remote_host"]; ?>' type='hidden'>

?>

with

<body>

<?php include("contactform.php"); ?>
</form>
</body>

-I've tried just including the php snippet in the html form

<form action="gdform.php" method="post"><input
 name="redirect" value="thankyou.html" type="hidden"><input
 name="subject" value="Website Contact" type="hidden">
<--more fields then-->
              <input id="ip" name="ip"
 value='<?php echo $_server["remote_address"]; ?>' type="hidden">
              <input id="host" name="host"
 value='<?php echo $_server["remote_host"]; ?>' type="hidden">
<input value="Submit" type="submit"><br>
      </form>

I hope this is enough that someone can point out what obvious mistake(s) I'm making.

(I can't get php to include anything, even a text footer, in my website. I read this thread http://www.daniweb.com/forums/thread200844.html an tried to do exactly)

this

<?php
              
<input id="ip" name="ip" size='25' value='<?php echo $_server["remote_address"]; ?>' type='text'>
<input id="host" name="host" value='<?php echo $_server["remote_host"]; ?>' type='hidden'>

?>

will fail, the outer <?php ?> is unneccesary,
dont make the fields text unless you want the user to see and alter them,
try

<input id="ip" name="ip"  value='<?php echo $_server["remote_address"]; ?>' type='hidden'>
<input id="host" name="host" value='<?php echo $_server["remote_host"]; ?>' type='hidden'>

or

<?php echo "<input id=\"ip\" name=\"ip\" value=\"".$_server['remote_address']."\" type=\"hidden\">";
echo "<input id=\"host\" name=\"host\" value=\"".$_server['remote_host']."\" type=\"hidden\">"; ?>

For php includes, or php embedded in the original html form, did you rename the "outer"form from "formname".html to "formname".php so the server will know to parse it for php
else the html parser will just find 'wrong' tags instead of the php parser parsing the php then sending the generated stuff on as html

Not sure the answer to this question. My page is html and called contact.html. There is one "form" in the page. The action is

<form action="gdform.php" method="post"><input
 name="redirect" value="thankyou.html" type="hidden"><input
 name="subject" value="Website Contact" type="hidden">
Standard form fields (within a table if that makes a difference). Then
<input value="Submit" type="submit"> </form>

Everything works and send to me except the IP/Host issue. The gdform.php contents are created by gd, and are listed in my first post. (I can edit it).

Tried the two different php options you gave me and did not work, but should I be creating a second form?

Thank you so much for your help!

For php includes, or php embedded in the original html form, did you rename the "outer"form from "formname".html to "formname".php so the server will know to parse it for php
else the html parser will just find 'wrong' tags instead of the php parser parsing the php then sending the generated stuff on as html

Thinking

back soon

can you post a few of the other form input fields from

<table>
<tr>
<td><input>
<tr><td><input>
<!--bla bla-->

the table may matter,
not sure of the format,

Here is the first part and last part of the table. There are a few other fields, but no different 'types'. There is one more 'select' list. They are just unformated text entry fields, identical to the "Name" field.
.

<form action="gdform.php" method="post"><input
 name="redirect" value="thankyou.html" type="hidden"><input
 name="subject" value="Website Contact" type="hidden">
        <table border="0" cellpadding="8"  cellspacing="0">
          <tbody>
            <tr>
              <td style="font-weight: bold; color: rgb(0, 51, 0);"><small>Name:</small></td>
              <td><input name="Name" id="Name" size="50" type="text"></td>
            </tr>
            <tr>
              <td
 style="vertical-align: top; text-align: left; font-weight: bold; color: rgb(0, 51, 0);">
              <small>Email address <br>
(if you'd like a reply)</small></td>
              <td><input name="Email" id="Email" size="50"></td>
            </tr>
            <tr>
              <td
 style="vertical-align: top; text-align: left; font-weight: bold; color: rgb(0, 51, 0);"><small>
Your Country</small></td>
              <td>
              <select name="Your Country" id="Your Country">
              <option value="">select one</option>
              <option value="USA">USA</option>
              <option value="Canada">Canada</option>
              <option value="Other">Other</option>
              </select>
              </td>
            </tr>
<tr>
              <td colspan="2"
 style="vertical-align: top; text-align: left; font-weight: bold; color: rgb(0, 51, 0);">
              <small>Comment, Question, or Help Requested<br>
              </small>
              <textarea rows="15" cols="60"
 name="comments" id="comments"></textarea><br>

<input id="ip" name="ip" value='<?php echo $_server["remote_address"]; ?>' type="hidden">
<input id="host" name="host" value='<?php echo $_server["remote_host"]; ?>' type="hidden">

              </td>
            </tr>
          </tbody>
        </table>

<--Also tried putting the php here, outside the table, made no difference-->
        <input value="Submit" type="submit"><br>

nope, the inputs are not special, IDs etc

thinking
back soon

FWIW

Currently the form includes this:

<input type='hidden' id='ip' name='ip' value='<?php echo $_server["remote_address"]; ?>'>
<input type='hidden' id='host' name='host' value='<?php echo $_server["remote_host"]; ?>'>

The contact responces is:
Email: foo
Name: Ilda endsley
Phone: 555-1212
Topic: whatever
Your_Country: USA
Your_State: Hawaii
comments: contact attempt, will it work?
host: <?php echo $_server["remote_host"]; ?>
ip: <?php echo $_server["remote_address"]; ?>

If I make the 2 input fields visible, it show the above entries in the entry part of the field.

I did put a request into godaddy (again) to see if they have any guidance.

I think I have the solution! will post more later today wiht my results!

the php is not being parsed in the form
is the form extension .php so that php in the form will be recognized
or is it still labelled .htm/.html
I have a mental blank on any other reason

commented: Thank you +3

Yes, you are right I was confused about the file extension.
Step 1 in solving my problem was to File Save As then change the extension to .php
I was confused about that, and originally tried renaming it, but also mangled some other things too.

Step 2
Here is the exact language that finally worked for me:

<input id="ip" name="ip" value="<?php echo ($_SERVER 'REMOTE_ADDR']); ?>" type="hidden">
              
<input id="host" name="host"  value="<?php $hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']); echo ($hostname); ?>" type="hidden">

I believe I had to use Caps to make it work.
REMOTE_HOST returned the same thing as REMOTE_ADDR for me, so I found the gethostbyaddr from some website today.

For other non-experts like me working on this problem, I found it useful to have the type="text" for my working models. Then once it is uploaded, you can 'see' right away whether it is actually pulling the IP.

Once I got it to work, I swtiched the type to "hidden".
<happy dance>

Thank you so much for your help!

Ditto <happy dance>
the next changes, will be easy
have you seen

<?php //stats.php
// Get the user stats.
$getdate = date( 'd-m-Y, H:i:s' );// Get the date.
$user_ip = $_SERVER['REMOTE_ADDR'];// Get the users IP.
$user_browser = $_SERVER['HTTP_USER_AGENT'];// Get the browser.
$referer = $_SERVER["HTTP_REFERER"];// Get the refering page.
// Look for the text file and open it for writting.
$file = "./logfiles/logfile.csv";// define the text file.
$fp = fopen($file, "a+");//open the text file for writing.
// Write the user stats into the text file.
fputs ($fp, "$user_ip,$getdate, $referer\n");
fclose($fp);// Close the text file.
?>

If you <?php include('./stats.php'); ?> in your files it creates a comma separated list of who went where and when.

just an :icon_evil: thought

You can log your site, even if you dont have access to the server logs
http://www.bbclone.de is "a web counter on steroids" the earlier screen dump is of a bbclone script page

Hadn;t seen that one. I've downloaded logs from my old host before, and godaddy seems to allow me to download as well.
Then I use the freebie webhostexpert lite to produce some stats etc.

But I have also been using an outside source 'statcounter' I think which produces nice free paths (but limited to 500 entries) of who visited which page in which order.

I'll look into your suggestion though to see what it might produce.

Every ISP I have ever used since 1998 has created dummy IP addresses. I haven't had dial-up since 1993.

The IP address the ISP gets is real. But anything it puts out on the Internet has a one-time throwaway IP address.

strange - the IP I get everytime I send the form is the same.
And looking at the site stats, the IP of many people who browse is the same - i know who they are.

I know it is possible to browse using anonymously, but the vast majority don't, or at least the vast majority of folks who visit my sites don't, so having the IP is helpful to me.

Every ISP I have ever used since 1998 has created dummy IP addresses. I haven't had dial-up since 1993.

The IP address the ISP gets is real. But anything it puts out on the Internet has a one-time throwaway IP address.

The IP is real, it is the ROUTING address, if it were not real the browser screen is blank, files not delivered

This thread I am starting is a carry over from this thread

http://www.daniweb.com/web-development/web-design-html-and-css/threads/205959/getting-ip-address-into-a-contact-form-field

Having the same issue as you bbq Karen. I have a form field (no PHP) code anywhere at this point that I wish to include the users IP address on the form as a hidden field like you did and pass it back to me when they contact us. Ok so this is what I have

  1. HTML form only
  2. The form does not call or execute any php. All the processing is done on the form itself.
  3. The form itself was a snippet provide to me by a CRM system I use but there is nothing rocket science about it.
  4. I need to pull the IP address as just one more hidden field and I would be set.
  5. I tried some of the things you did above.
  6. The first thing was to simply copy all the html code to a new file with a .php extension publish the file and the page comes up just fine and works.
  7. The minute I make a change to the file and re-publish. Something breaks and the page does not come up anymore.

I am ready to send you guys whatever you need. I work in IT but not a web guy per say. Just doing some support for my wifes website.

Any help would be greatly appreciated.
GSam777

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.