954,598 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Getting IP address into a contact form field

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"]."/");
	}
?>
bbqkaren
Newbie Poster
20 posts since Oct 2006
Reputation Points: 10
Solved Threads: 0
 

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.

MidiMagic
Nearly a Senior Poster
3,319 posts since Jan 2007
Reputation Points: 730
Solved Threads: 182
 

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.

bbqkaren
Newbie Poster
20 posts since Oct 2006
Reputation Points: 10
Solved Threads: 0
 

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

Attachments untitled.jpg 230.6KB
almostbob
Posting Sensei
3,149 posts since Jan 2009
Reputation Points: 571
Solved Threads: 376
 

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

bbqkaren
Newbie Poster
20 posts since Oct 2006
Reputation Points: 10
Solved Threads: 0
 

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">
      </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)

bbqkaren
Newbie Poster
20 posts since Oct 2006
Reputation Points: 10
Solved Threads: 0
 

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

almostbob
Posting Sensei
3,149 posts since Jan 2009
Reputation Points: 571
Solved Threads: 376
 

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

bbqkaren
Newbie Poster
20 posts since Oct 2006
Reputation Points: 10
Solved Threads: 0
 

Thinking

back soon

almostbob
Posting Sensei
3,149 posts since Jan 2009
Reputation Points: 571
Solved Threads: 376
 

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,

almostbob
Posting Sensei
3,149 posts since Jan 2009
Reputation Points: 571
Solved Threads: 376
 

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 
(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
              </small>
              <textarea rows="15" cols="60"
 name="comments" id="comments"></textarea>

<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">
bbqkaren
Newbie Poster
20 posts since Oct 2006
Reputation Points: 10
Solved Threads: 0
 

nope, the inputs are not special, IDs etc

thinking
back soon

almostbob
Posting Sensei
3,149 posts since Jan 2009
Reputation Points: 571
Solved Threads: 376
 

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.

bbqkaren
Newbie Poster
20 posts since Oct 2006
Reputation Points: 10
Solved Threads: 0
 

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

bbqkaren
Newbie Poster
20 posts since Oct 2006
Reputation Points: 10
Solved Threads: 0
 

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

almostbob
Posting Sensei
3,149 posts since Jan 2009
Reputation Points: 571
Solved Threads: 376
 

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

Thank you so much for your help!

bbqkaren
Newbie Poster
20 posts since Oct 2006
Reputation Points: 10
Solved Threads: 0
 

Ditto
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

almostbob
Posting Sensei
3,149 posts since Jan 2009
Reputation Points: 571
Solved Threads: 376
 

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.

bbqkaren
Newbie Poster
20 posts since Oct 2006
Reputation Points: 10
Solved Threads: 0
 

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.

MidiMagic
Nearly a Senior Poster
3,319 posts since Jan 2007
Reputation Points: 730
Solved Threads: 182
 

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.

bbqkaren
Newbie Poster
20 posts since Oct 2006
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You