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

In the thread above BBQKAREN and ALMOSTBOB was able to resolve her issue wich is the same issue I have but I have no way of contacting THEM here.

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 she 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 bbqkaren did in her thread above but no avail.

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 ANY change to the php file and re-publish. Something breaks and the page does not come up anymore.

  1. I am familiar with some PHP and have a simple PHP file that displays the REMOTE_ADDRESS Ip address on the screen after I publish the file to my hosting company. What this means is that PHP works for me.

  2. I am already using the REMOTE_ADDRESS field on a contact us page and sucessfully am sending it back when they send us an email but now I want to use it on the REGISTRATION PAGE and send IP address back to me as one of the fields for me to record.

I am ready to provide whatever we need here on the thread. 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

Recommended Answers

All 19 Replies

Member Avatar for diafol

I don't sdee why you need to pass the IP Address. You're going to process the form in php anyway right? So just grab the IP Address then. Otherwise, someone could spoof the data easily - never trust any data from a form.

As diafol above, the ip address is available to the form handler

the form processor scrpt supplied by ISP can be often configured to capture the IP address, and other common data, without an input in the html form
simple as reading the helpscreens for the particular script
more exact, can't be, without seeing the code of the form handler\ for a neat secure answer

but just like Karen, you can rename the form to .php and use
<input type='hidden' value='<?php echo $_SERVER["REMOTE_ADDRESS"]; ?>' name='IP'>

DIAFOL - you are correct if the page interacted with PHP but it does not. This page that I have is STRICTLY HTML. It is a registration page and the registration portion of the page was a form snippet that was provied to me by a CRM vendor we use so that the form interacts with their system (pretty cool). All I had to do was clean it up and it worked.

ALMOSTBOB - you are right as well however I need to get my html to work as or with a PHP file or some flavor of that (not sure that is where I have my disconnect) then I am sure your REMOVE_ADDRESS code above will work.

The following is a mouthful but I am trying to convey as much as I can. I work in IT and I know what it is to not have a deep enough explanation of an issue so to help this moving along.

1. THE FOLLOWING IS ALL THE HTML CODE AND THE FILE ENDS IN .html

2. I have highlighted for you in BOLD where the form begins and ends to help save you some time. All the form code is located between these two comments labeled: <!--Zoho Form -->

3. Also note and I do show the IP address on the screen using a third party call to an external .php using www.whatsmyip.us website. This for now is just for display to scare off any potential spammers and not to be confused with what I would like to do which is to send it back to me as a hidden field. In the end I may still want to show it on the screen but that is NICE TO HAVE.

4. If you wish to call up the page you can do so as html at:

http://www.xoomcargo.com/new/index-eng-register2.html

5. Other information - I have a php posted on my website that works and displays the IP address using the REMOTE_ADDR code to see that in action call http://www.xoomcargo.com/new/php/yourip.php
the php code is simple

<?php 
echo $_SERVER['REMOTE_ADDR']; 
?>

HTML Code ending in .html

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Register</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="style.css" rel="stylesheet" type="text/css" />
<link href="layout.css" rel="stylesheet" type="text/css" />
<script src="js/jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="js/cufon-yui.js" type="text/javascript"></script>
<script src="js/cufon-replace.js" type="text/javascript"></script>
<script src="js/Swis721_Th_BT_400.font.js" type="text/javascript"></script>

<link href="http://www.xoomcargo.com/favicon.ico" rel="shortcut icon" type="image/x-icon"/>
<link href="http://www.xoomcargo.com/favicon.ico" rel="icon" type="image/x-icon"/>

<style type="text/css">
.style1 {
    border: 2px solid #FF0000;
}
</style>

</head>

<body id="page7">
<div class="bg_tail">
    <div class="bg_header">
    <div id="main">
        <!--header -->
        <div id="header" class="main" style="height: 192px">
        <div class="menu" style="height: 113px">
            <ul>
                <li><a href="index-eng-home.html">Company</a></li>
                <li><a href="index-eng-register2.html"  class="active">Register</a></li>
                <li><a href="index-eng-services.html">Services</a></li>
                <li><a href="index-eng-contactus.html">Contact Us</a></li>
                <li><a href="index-eng-payments.html">Payments</a></li>
                <li><a href="index-esp-home.html">Espanol</a></li>
                <li><a href="index-eng-news.html" class="last">News</a></li>
            </ul>
        </div>


<!--logo header-->
<div class="wrapper" style="height: 110px">
<table style="width: 100%">
<tr>
<td style="width: 505px">
<a href="index-eng-home.html"><img alt="" src="images2/xc-logoeng.png"/></a>&nbsp;<br />
<span style="font-size: 10pt">Cargo and package shipments from the United States to Colombia and Venezuela</span></td>
<td style="text-align: right" valign="bottom">Toll Free - USA - 888.417.5215<br />Local - USA - 786.299.5000</td>
</tr>
<!--Row 2 -->
<tr>
<td colspan="2">&nbsp;</td>
</tr>

</table>
</div>
<!--logo header-->

</div>
<!--header end-->


            <div class="row2" style="height: 676px">
                <div class="main" style="height: 707px">
                    <div class="wrapper" style="height: 707px">
                        <div class="col1 cols" style="width: 940px; height: 695px;">
                            <h4 style="height: 7px">REGISTER WITH XOOM CARGO</h4>
**<!--Zoho Form -->**    

<div id='crmWebToEntityForm' align="center"><META HTTP-EQUIV ='content-type' CONTENT='text/html;charset = UTF-8'>  
<form action='https://crm.zoho.com/crm/WebToContactForm'  name=WebToContacts209935000005044007 method='POST' onSubmit='javascript:document.charset="UTF-8"; return checkMandatery()' accept-charset='UTF-8'>

    <table border=0 cellspacing=0 cellpadding=5 style='width: 741px;' class="style1">  
    <input type='text' style='display:none;' name='xnQsjsdp' value='YAQMzvVNd4s$'/>  
    <input type='hidden' name='zc_gad' id='zc_gad' value=''/>  
    <input type='text' style='display:none;' name='xmIwtLD' value='wW73F6WP5BcMXscF9gY1cAw1vyXgS1pG'/>  
    <input type='text'  style='display:none;' name='actionType' value='Q29udGFjdHM='/> 
    <input type='text' style='display:none;' name='returnURL' value='http://www.xoomcargo.com/xc_zoho_reg_engspa_thx.html' />
    <tr><td nowrap style='font-family:sans-serif;font-size:12px;font-weight:bold; text-align: left;' colspan="2">
        &nbsp;</td>
        </tr>
    <tr><td nowrap style='font-family:sans-serif;font-size:12px;font-weight:bold; text-align: left;' colspan="2">
        &nbsp;
        Enter your registration information - <span style="color: #FF0000">
        (*)</span> are mandatory fields&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
        <a href="index-spa-register.html"><span style="color: #FFFFFF">Inscribirse en Espanol haga clic aqui</span></a></td>
        </tr>
    <tr><td nowrap style='font-family:sans-serif;font-size:12px;font-weight:bold; text-align: left;' colspan="2">
        &nbsp;</td>
        </tr>

    <tr><td nowrap style='font-family:sans-serif;font-size:12px;font-weight:bold; height: 30px; width: 259px; text-align: right;'>
        <span style="color: #FF0000">(*)</span>&nbsp; First Name &nbsp;&nbsp;:&nbsp;&nbsp;  </td>
    <td style="height: 30px; width: 280px; text-align: left;">
    <input style="color:#000000; width: 200px;" type='text' maxlength='40' name='First Name' style="width: 200px" /> </td></tr>

    <tr><td nowrap style='font-family:sans-serif;font-size:12px;font-weight:bold; width: 259px; height: 30px; text-align: right;'>
    <span style="color: #FF0000">(*)</span>&nbsp; Last Name &nbsp;&nbsp;:&nbsp;&nbsp;</td>
    <td style="width: 280px; height: 30px; text-align: left;">
    <input style="color:#000000; width: 200px;" type='text' maxlength='80' name='Last Name' style="width: 200px" /> </td></tr>

    <tr><td nowrap style='font-family:sans-serif;font-size:12px;font-weight:bold; width: 259px; height: 30px; text-align: right;'>
        <span style="color: #FF0000">(*)</span>&nbsp; Email &nbsp;&nbsp;:&nbsp;&nbsp;</td>
    <td style="width: 280px; height: 30px; text-align: left;">
    <input style="color:#000000; width: 200px;" type='text' maxlength='100' name='Email' style="width: 200px" /> </td></tr>

    <tr><td nowrap style='font-family:sans-serif;font-size:12px;font-weight:bold; width: 259px; height: 30px; text-align: right;'>
    <span style="color: #FF0000">(*) </span>&nbsp;Phone (no spaces) &nbsp;&nbsp;:&nbsp;&nbsp;</td>
    <td style="width: 280px; height: 30px; text-align: left;">
    <input style="color:#000000; width: 200px;" type='text' maxlength='50' name='Phone' style="width: 200px" /> </td></tr>

    <tr><td nowrap style='font-family:sans-serif;font-size:12px;font-weight:bold; width: 259px; height: 30px; text-align: right;'>Mobile&nbsp; 
        (no spaces)&nbsp;&nbsp;:&nbsp;&nbsp;</td>
    <td style="width: 280px; height: 30px; text-align: left;">
    <input style="color:#000000; width: 200px;" type='text' maxlength='30' name='Mobile' style="width: 200px" /> </td></tr>

    <tr><td nowrap style='font-family:sans-serif;font-size:12px;font-weight:bold; width: 259px; height: 30px; text-align: right;'>
    <span style="color: #FF0000">(*)</span>&nbsp; Mailing Street &nbsp;&nbsp;:&nbsp;&nbsp;</td>
    <td style="width: 280px; height: 30px; text-align: left;">
    <input style="color:#000000; width: 200px;" type='text' maxlength='250' name='Mailing Street' style="width: 200px" /> </td></tr>

    <tr><td nowrap style='font-family:sans-serif;font-size:12px;font-weight:bold; width: 259px; height: 30px; text-align: right;'>Mailing Street 2 &nbsp;&nbsp;:&nbsp;&nbsp;</td>
    <td style="width: 280px; height: 31px; text-align: left;">
    <input style="color:#000000; width: 200px;" type='text' maxlength='40' name='CONTACTCF1' style="width: 200px" /> </td></tr>

    <tr><td nowrap style='font-family:sans-serif;font-size:12px;font-weight:bold; width: 259px; height: 30px; text-align: right;'>
        <span style="color: #FF0000">(*)</span>&nbsp; Mailing City &nbsp;&nbsp;:&nbsp;&nbsp;</td>
    <td style="width: 280px; height: 29px; text-align: left;">
    <input style="color:#000000; width: 200px;" type='text' maxlength='30' name='Mailing City' style="width: 200px" /> </td></tr>

    <tr><td nowrap style='font-family:sans-serif;font-size:12px;font-weight:bold; width: 259px; height: 30px; text-align: right;'>Mailing State &nbsp;&nbsp;:&nbsp;&nbsp;</td>
    <td style="width: 280px; height: 30px; text-align: left;">
    <input style="color:#000000; width: 200px;" type='text' maxlength='30' name='Mailing State' style="width: 200px" /> </td></tr>

    <tr><td nowrap style='font-family:sans-serif;font-size:12px;font-weight:bold; width: 259px; height: 30px; text-align: right;'>Mailing Zip &nbsp;&nbsp;:&nbsp;&nbsp;</td>
    <td style="width: 280px; height: 30px; text-align: left;">
    <input style="color:#000000" type='text' maxlength='30' name='Mailing Zip' style="width: 150px" /> </td></tr>

<!-- Country -->     
    <tr><td nowrap style='font-family:sans-serif;font-size:12px;font-weight:bold; height: 30px; width: 259px; text-align: right;'>
        <span style="color: #FF0000">(*)</span>&nbsp; Mailing Country &nbsp;&nbsp;:&nbsp;&nbsp;</td>

    <td style="height: 30px; width: 280px; text-align: left;">
    <input style="color:#000000" style="width: 150px;" type='text' maxlength='30' name='Mailing Country'
    style="width: 150px" value="" /> </td></tr>

    <tr><td nowrap style='font-family:sans-serif;font-size:12px;font-weight:bold; width: 259px; height: 58px; text-align: right;'>
    Notes &nbsp;&nbsp;:&nbsp;&nbsp;</td>
    <td style="width: 280px; height: 58px; text-align: left;"> 
    <textarea name='Description' style="color:#000000; width: 228px; height: 48px;" maxlength='32000' style="width: 200px"  ></textarea> </td></tr>

    <tr><td nowrap style='font-family:sans-serif;font-size:12px;font-weight:bold; width: 259px; height: 58px; text-align: right;'>
        &nbsp;</td>
    <td style="width: 280px; height: 58px; text-align: left;"> 

    <br />

    <input type='submit' name='save' value=Save style="color:#000000" style="width: 100px" /> &nbsp; &nbsp; 
    <input type='reset' name='reset' value=Reset style="color:#000000" style="width: 100px" />

    <br />
    <br />

<!-- IP Address -->                                      
<div style="text-align: left">
<span style="color: #616161">Your IP is: <script type="text/javascript" src="http://www.whatsmyip.us/showipsimple.php"> </script>
</span>
</div>
<!-- End IP Address -->

</td></tr>

    <tr><td nowrap style='font-family:sans-serif;font-size:12px;font-weight:bold; width: 259px; height: 18px;' align='right'>
        </td>
    <td style="width: 280px; height: 18px; text-align: left;"> 

</td></tr>

</table>

    <script> var mndFileds=new Array('First Name','Last Name','Email','Phone','Mailing Street','Mailing City','Mailing Country');var fldLangVal=new Array('First Name','Last Name','Email','Phone','Mailing Street','Mailing City','Mailing Country');function checkMandatery(){for(i=0;i<mndFileds.length;i++){ var fieldObj=document.forms['WebToContacts209935000005044007'][mndFileds[i]];if(fieldObj) {if(((fieldObj.value).replace(/^\s+|\s+$/g, '')).length==0){alert(fldLangVal[i] +' cannot be empty'); fieldObj.focus(); return false;}else if(fieldObj.nodeName=='SELECT'){if(fieldObj.options[fieldObj.selectedIndex].value=='-None-'){alert(fldLangVal[i] +' cannot be none'); fieldObj.focus(); return false;}}}}}</script>

    </form></div>

**<!--Zoho Form End -->**

<!-- Zoho Live Desk -->                              
<script src="js/zld-eng-embed1.js" type="text/javascript"></script>
<script src="js/zld-eng-embed2.js" type="text/javascript"></script>
<!-- Zoho Live Desk -->              

<div class="wrapper" style="text-align: justify">
    <p style="line-height: 100%"><span style="color: #616161">
    <br />
    </span><span style="color: #616161; font-size: xx-small;">
    By registering with or accepting registration from Xoom Cargo through their 
    automated computer systems to transport cargo on your behalf.&nbsp; You authorize Xoom Cargo under the rules and regulations of the Transportation 
    Security Administration (TSA) in the United States, to receive, manage, store and ship cargo on your behalf.&nbsp; You also authorize Xoom Cargo to 
    search, screening or inspection of your cargo.  Electronic registration in our automated systems and an email confirmation sent to you on behalf of 
    Xoom Cargo serves as an electronic signature and confirmation on your behalf.</span></p>
                            </div>


                        </div>
                    </div>
                </div>               
            </div>

<!-- Begin Footer -->
            <div class="row3" style="height: 130px">
                <div class="main">
                    <div class="wrapper">
                        <div class="left">
                            <div>

                                <h3>About Us</h3>
                                <ul>
                                    <li><a href="index-eng-home.html">About</a></li>
                                    <li><a href="index-eng-services.html">Services</a></li>
                                    <li><a href="index-eng-register2.html">Contact Us</a></li>
                                    <li><a href="index-esp-home.html">Espanol</a></li>

                                </ul>
                            </div>
                            <div>
                                <h3>Support</h3>
                                <ul>
                                    <li><a href="index-eng-register2.html">Register</a></li>
                                    <li><a href="index-eng-payments.html">Payments</a></li>
                                    <li><a href="index-eng-tools.html">Tools</a></li>

                                </ul>
                            </div>
                            <div>
                                <h3>Advice</h3>
                                <ul>
                                    <li><a href="index-eng-faq.html">FAQs</a></li>
                                </ul>

                            </div>
                            <div>
                                <h3>News</h3>
                                <ul>
                                    <li><a href="index-eng-news.html">News</a></li>
                                </ul>
                            </div>
                        </div>
                        <div class="right">
                            <h3>Other Links</h3>

                                <div>
                                <ul>
                                    <li><a href="#">Site Map</a></li>
                                    <li><a href="index.html">Home</a></li>
                                </ul>

                                </div>
<!-- End Footer -->
                        </div>
                    </div>
                </div>               
            </div>
        </div>

<!--footer -->
<div id="footer">
<div class="main">
<p>Xoom Cargo ©&nbsp;2010-<script src="js/currentyear.js" type="text/javascript"></script>     
&bull; <a href="index-eng-privacy.html">Privacy Policy</a>
&bull; <a href="index-eng-termsofuse.html">Terms of Use</a>
</p>
</div>
</div>
<!--footer end-->

    </div>
   <script type="text/javascript"> Cufon.now(); </script>
  </div>


<!------- Google Analytics   ------->

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-33232838-1']);
  _gaq.push(['_setDomainName', 'xoomcargo.com']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>

<!------ End Google Analytics ------>


</body>

</html>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Please disregard the ~~~~~~~~~~~~~~ in rows 1 & 307 above. I was trying to divide the code away from the explanation but this is my first time on this forum and I see the code snippet already does a nice job of that. The ~~~~~~ are not in my code.

ALMOSTBOB - you are right as well however I need to get my html to work as or with a PHP file or some flavor of that (not sure that is where I have my disconnect) then I am sure your REMOVE_ADDRESS code above will work.

This is a server configuration issue so, do it with .htaccess Put a file named .htaccess << (notice the period in front ) in the htdocs of your server (eg: public html) or where your source folder is. Input either rule below that you need or prefer.

This will change all .html files on your server so that they can execute php

AddType application/x-httpd-php .html

or if you just want php on your registration page :

<Files index-eng-register2.html>
AddType application/x-httpd-php .html
</Files>

Banderson thanks for the feedback I am not familiar with this so I have a few comments and questions.

COMMENTS
1. I do not run my own server my pages are hosted by HOSTWAY.com so access to server configurations I would need to run by them if needed and or access to the htdocs folder.

QUESTIONS

1. Regarding the .htaccess file

a. Does the file need to have some type of prefix in front of the period?  Like xxx.htaccess?

b. I am rebuilding my wifes website so I have working out of a subdirectory called "new"
   see exmaple path here:  http://www.xoomcargo.com/new/index-eng-register2.html

c. Do you suggest I put the .htaccess file in the "new" folder or one level
   up in the main root folder?

d. I will go with the "AddType application/x-httpd-php .html" but my question here
   is will it affect the html pages that are already there in any way?

c. Am I to understand this right that doing the above will allow me to put
   code in my html file such as what ALMOST BOB sent me below and it should work ?:

   **<input type='hidden' value='<?php echo $_SERVER["REMOTE_ADDRESS"]; ?>' name='IP'>**

d. Do I need to rename my html file to .PHP and  place the respective .php codes below at the top
   and bottom of my html?

   <?php 
    ?> 

Thanks in advance
Gsam777

a no, the .htaccess filename is specific
bc The action of .htaccess continues to subfolders, If you put a .htaccess in the root, it covers subfolders, may require directives that you dont wish for the root, so you put another .htaccess in a subfolder specific to that subfolder. there can be as many .htaccess files as the site requires

your hosted form processor. DOES support automatic IP collection you do not need to make a form change, you need to make a configuaration change

Ok latest update.

  1. I created the .htaccess file and loaded it up to my web hosting company
  2. The one line line of code I included in the file was

    AddType application/x-httpd-php .html

  3. I also included the following line of code to retrieve the ip address

    <input style="color:#000000" style="width: 200px;" type='text' maxlength='50' name='ip'
    style="width: 200px" value='<?php echo $_SERVER["REMOTE_ADDR"]; ?>' />

  4. You can visit the url here to see the code still loaded up however I had to remove the .htaccess file which you cannot see http://www.xoomcargo.com/new/index-eng-register2.html

** RESULTS ISSUE 1 **

I did not work for a few reasons

  1. First and foremost the page would not pull the IP address. I know the field was not hidden, I did this on purpose because in the previous article above BBQKAREN made a comment that it was easier to debug if you mande the field type "text" until it was working then simply go back and make it hidden.

None the less the code is not pulling in the IP address. Almostbob I noticed that you had sent the code line to look line this

<input type='hidden' value='<?php echo $_SERVER["REMOTE_ADDRESS"]; ?>' name='IP'>

However I believe that REMOTE_ADDRESS should have been abbreviated to look like this REMOTE_ADDR. If this is wrong let me know but I tried both and either did not work.

  1. The good news is that the code did not go crazy on me and the page did come up but not with the IP address in it.

** RESULTS ISSUE 2 **

  1. This one is weird. The page will not load up with FIREFOX. Firefox pops up a window asking me if I want to open the page with say IE. That is really wierd. The page does come up in IE again without the IP address. As a matter of fact all the pages in this subfolder are not coming up with this message. To test go here as well which is not the registration page. http://www.xoomcargo.com/new/index-eng-home.html

After removing the .htaccess file firefox pulls up the page without the popup but of course no ip.

** CURRENT STATUS **

I left the .htaccess file loaded up so you can see what I am talking about and if you pull up the page on the link above you will see the results I am getting.
Comments or corrections to code are welcomed.

One final note I had to add the style="color:#000000" code because my backround in the form field is white so I need the text black or else it will not show up. I can always remove that later once I go hidden.

Thanks in advance
Gsam777

Member Avatar for diafol

I left the .htaccess file loaded up so you can see what I am talking about and if you pull up the page on the link above you will see the results I am getting.

It doesn't seem so. You cannot run php in a html page unless you have the .htaccess file up and running. Consequently, you are showing your php code within the textbox.

I will reiterate my point. If you send a html form to the server, you'll be using php anyway to handle the form input data. Why not just tag on the IP address there - there's absolutely no need to pass this info via the form. That way, you can leave the form clean from php if you wish, unless you want to populate the form with default or previously supplied data from the user.

IMO, you're trying to achieve something that is simply unnecessary.

For example, when you process the form data:

if(isset($_POST['save']))
{
    $ip = $_SERVER['REMOTE_ADDR'];
    $email = $_POST['email'];
    //etc etc
}

//EDIT

Just re-read:

This for now is just for display to scare off any potential spammers and not to be confused with what I would like to do which is to send it back to me as a hidden field. In the end I may still want to show it on the screen but that is NICE TO HAVE.

Well, in that case use:

<p>Your IP Address: <?php echo $_SERVER['REMOTE_ADDR'];?></p>

But not in html file unless you have the .htaccess thing going on.

DO NOT rely on this as forms and headers can be spoofed and total rubbish passed on to the server. Unless you have some sort of good CSRF routine, then you can't rely say for sure that form data came from your domain. Even then...

Diafol I appreciate you anwser and I kinda get what you are saying trust me I don't want to do any more work than I have to but in my previous post I stated that:

The .htaccess is STILL uploaded to my web hosting company server. I never deleted it so it is still there.

I wish so say again. The code below is a snippet code given to me by my CRM company that we use so the can code an html page to allow potential subscribers to register with us. Once they do that data is generated in our CRM system automatically.

I do not have access to any other code other that what I am showing below. If I had their PHP file I would simply as you said code the IP address update there and done but I do not. Unless I am grossly missing something here.

I attached below the form code from beginning to end showing the form itself that was given to me. All we do is clean up the colors / look & feel and it works.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Are we back to square 1?

<div id='crmWebToEntityForm' align="center"><META HTTP-EQUIV ='content-type' CONTENT='text/html;charset = UTF-8'>  
<form action='https://crm.zoho.com/crm/WebToContactForm'  name=WebToContacts209935000005044007 method='POST' onSubmit='javascript:document.charset="UTF-8"; return checkMandatery()' accept-charset='UTF-8'>

    <table border=0 cellspacing=0 cellpadding=5 style='width: 741px;' class="style1">  
    <input type='text' style='display:none;' name='xnQsjsdp' value='YAQMzvVNd4s$'/>  
    <input type='hidden' name='zc_gad' id='zc_gad' value=''/>  
    <input type='text' style='display:none;' name='xmIwtLD' value='wW73F6WP5BcMXscF9gY1cAw1vyXgS1pG'/>  
    <input type='text'  style='display:none;' name='actionType' value='Q29udGFjdHM='/> 
    <input type='text' style='display:none;' name='returnURL' value='http://www.xoomcargo.com/xc_zoho_reg_engspa_thx.html' />
    <tr><td nowrap style='font-family:sans-serif;font-size:12px;font-weight:bold; text-align: left;' colspan="2">
        &nbsp;</td>
        </tr>
    <tr><td nowrap style='font-family:sans-serif;font-size:12px;font-weight:bold; text-align: left;' colspan="2">
        &nbsp;
        Enter your registration information - <span style="color: #FF0000">
        (*)</span> are mandatory fields&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
        <a href="index-spa-register.html"><span style="color: #FFFFFF">Inscribirse en Espanol haga clic aqui</span></a></td>
        </tr>
    <tr><td nowrap style='font-family:sans-serif;font-size:12px;font-weight:bold; text-align: left;' colspan="2">
        &nbsp;</td>
        </tr>

    <tr><td nowrap style='font-family:sans-serif;font-size:12px;font-weight:bold; height: 30px; width: 259px; text-align: right;'>
        <span style="color: #FF0000">(*)</span>&nbsp; First Name &nbsp;&nbsp;:&nbsp;&nbsp;  </td>
    <td style="height: 30px; width: 280px; text-align: left;">
    <input style="color:#000000; width: 200px;" type='text' maxlength='40' name='First Name' style="width: 200px" /> </td></tr>

    <tr><td nowrap style='font-family:sans-serif;font-size:12px;font-weight:bold; width: 259px; height: 30px; text-align: right;'>
    <span style="color: #FF0000">(*)</span>&nbsp; Last Name &nbsp;&nbsp;:&nbsp;&nbsp;</td>
    <td style="width: 280px; height: 30px; text-align: left;">
    <input style="color:#000000; width: 200px;" type='text' maxlength='80' name='Last Name' style="width: 200px" /> </td></tr>

    <tr><td nowrap style='font-family:sans-serif;font-size:12px;font-weight:bold; width: 259px; height: 30px; text-align: right;'>
        <span style="color: #FF0000">(*)</span>&nbsp; Email &nbsp;&nbsp;:&nbsp;&nbsp;</td>
    <td style="width: 280px; height: 30px; text-align: left;">
    <input style="color:#000000; width: 200px;" type='text' maxlength='100' name='Email' style="width: 200px" /> </td></tr>

    <tr><td nowrap style='font-family:sans-serif;font-size:12px;font-weight:bold; width: 259px; height: 30px; text-align: right;'>
    <span style="color: #FF0000">(*) </span>&nbsp;Phone (no spaces) &nbsp;&nbsp;:&nbsp;&nbsp;</td>
    <td style="width: 280px; height: 30px; text-align: left;">
    <input style="color:#000000; width: 200px;" type='text' maxlength='50' name='Phone' style="width: 200px" /> </td></tr>

    <tr><td nowrap style='font-family:sans-serif;font-size:12px;font-weight:bold; width: 259px; height: 30px; text-align: right;'>Mobile&nbsp; 
        (no spaces)&nbsp;&nbsp;:&nbsp;&nbsp;</td>
    <td style="width: 280px; height: 30px; text-align: left;">
    <input style="color:#000000; width: 200px;" type='text' maxlength='30' name='Mobile' style="width: 200px" /> </td></tr>

    <tr><td nowrap style='font-family:sans-serif;font-size:12px;font-weight:bold; width: 259px; height: 30px; text-align: right;'>
    <span style="color: #FF0000">(*)</span>&nbsp; Mailing Street &nbsp;&nbsp;:&nbsp;&nbsp;</td>
    <td style="width: 280px; height: 30px; text-align: left;">
    <input style="color:#000000; width: 200px;" type='text' maxlength='250' name='Mailing Street' style="width: 200px" /> </td></tr>

    <tr><td nowrap style='font-family:sans-serif;font-size:12px;font-weight:bold; width: 259px; height: 30px; text-align: right;'>Mailing Street 2 &nbsp;&nbsp;:&nbsp;&nbsp;</td>
    <td style="width: 280px; height: 31px; text-align: left;">
    <input style="color:#000000; width: 200px;" type='text' maxlength='40' name='CONTACTCF1' style="width: 200px" /> </td></tr>

    <tr><td nowrap style='font-family:sans-serif;font-size:12px;font-weight:bold; width: 259px; height: 30px; text-align: right;'>
        <span style="color: #FF0000">(*)</span>&nbsp; Mailing City &nbsp;&nbsp;:&nbsp;&nbsp;</td>
    <td style="width: 280px; height: 29px; text-align: left;">
    <input style="color:#000000; width: 200px;" type='text' maxlength='30' name='Mailing City' style="width: 200px" /> </td></tr>

    <tr><td nowrap style='font-family:sans-serif;font-size:12px;font-weight:bold; width: 259px; height: 30px; text-align: right;'>Mailing State &nbsp;&nbsp;:&nbsp;&nbsp;</td>
    <td style="width: 280px; height: 30px; text-align: left;">
    <input style="color:#000000; width: 200px;" type='text' maxlength='30' name='Mailing State' style="width: 200px" /> </td></tr>

    <tr><td nowrap style='font-family:sans-serif;font-size:12px;font-weight:bold; width: 259px; height: 30px; text-align: right;'>Mailing Zip &nbsp;&nbsp;:&nbsp;&nbsp;</td>
    <td style="width: 280px; height: 30px; text-align: left;">
    <input style="color:#000000" type='text' maxlength='30' name='Mailing Zip' style="width: 150px" /> </td></tr>

<!-- Country -->     
    <tr><td nowrap style='font-family:sans-serif;font-size:12px;font-weight:bold; height: 30px; width: 259px; text-align: right;'>
        <span style="color: #FF0000">(*)</span>&nbsp; Mailing Country &nbsp;&nbsp;:&nbsp;&nbsp;</td>

    <td style="height: 30px; width: 280px; text-align: left;">



    <input style="color:#000000" style="width: 150px;" type='text' maxlength='30' name='Mailing Country'
    style="width: 150px" value="" /> </td></tr>



    <tr><td nowrap style='font-family:sans-serif;font-size:12px;font-weight:bold; width: 259px; height: 58px; text-align: right;'>
    Notes &nbsp;&nbsp;:&nbsp;&nbsp;</td>
    <td style="width: 280px; height: 58px; text-align: left;"> 
    <textarea name='Description' style="color:#000000; width: 228px; height: 48px;" maxlength='32000' style="width: 200px"  ></textarea> </td></tr>

    <tr><td nowrap style='font-family:sans-serif;font-size:12px;font-weight:bold; width: 259px; height: 58px; text-align: right;'>
        04</td>
    <td style="width: 280px; height: 58px; text-align: left;"> 


    <input style="color:#000000" style="width: 200px;" type='text' maxlength='50' name='ip'
    style="width: 200px" value='<?php echo $_SERVER["REMOTE_ADDR"]; ?>' /> </td></tr>




    <tr><td nowrap style='font-family:sans-serif;font-size:12px;font-weight:bold; width: 259px; height: 58px; text-align: right;'>
        &nbsp;</td>
    <td style="width: 280px; height: 58px; text-align: left;"> 

    <br />

    <input type='submit' name='save' value=Save style="color:#000000" style="width: 100px" /> &nbsp; &nbsp; 
    <input type='reset' name='reset' value=Reset style="color:#000000" style="width: 100px" />

    <br />
    <br />

<!-- IP Address -->                                      
<div style="text-align: left">
<span style="color: #616161">Your IP is: <script type="text/javascript" src="http://www.whatsmyip.us/showipsimple.php"> </script>
</span>
</div>
<!-- End IP Address -->

</td></tr>

    <tr><td nowrap style='font-family:sans-serif;font-size:12px;font-weight:bold; width: 259px; height: 18px;' align='right'>
        </td>
    <td style="width: 280px; height: 18px; text-align: left;"> 

</td></tr>

</table>

    <script> var mndFileds=new Array('First Name','Last Name','Email','Phone','Mailing Street','Mailing City','Mailing Country');var fldLangVal=new Array('First Name','Last Name','Email','Phone','Mailing Street','Mailing City','Mailing Country');function checkMandatery(){for(i=0;i<mndFileds.length;i++){ var fieldObj=document.forms['WebToContacts209935000005044007'][mndFileds[i]];if(fieldObj) {if(((fieldObj.value).replace(/^\s+|\s+$/g, '')).length==0){alert(fldLangVal[i] +' cannot be empty'); fieldObj.focus(); return false;}else if(fieldObj.nodeName=='SELECT'){if(fieldObj.options[fieldObj.selectedIndex].value=='-None-'){alert(fldLangVal[i] +' cannot be none'); fieldObj.focus(); return false;}}}}}</script>

    </form></div>
Member Avatar for diafol

OK

<input style="color:#000000" style="width: 200px;" type='text' maxlength='50' name='ip'
style="width: 200px" value='<?php echo $_SERVER["REMOTE_ADDR"]; ?>' /> </td></tr>

Is was I see in browser source view. That should never happen if your .htaccess is set up properly. So, it seems that your .htaccess file may not set up properly.

In addition, when I clicked the 'switch to Spanish' link, it started a download of the html page. Definitely something weird going on there - assuming with your .htaccess file.

OK I noticed that you're sending info to a zoho crm site, which you have no control over. Unfortunate as you don't seem to have any control about how your data is processed/saved. I may be wrong.

Are you sure that your web hosting supports php files?

As for not using php files - if your hosting does support php, I can't see that there's anything stopping you from renaming the site files from *.html to *.php

So I'm still a bit confused.

third & last time, read the helpscreens, zoho crm contact form does support ip address collection

almostbob, I am going to research this option in ZOHO and get back to you. I am going as far as posting a question on their forum. So please stay tuned.

Diafol you are right I do not have control once I submit my data to the zoho site. To answer your inquiry about the .htaccess file please see below.

** First **

This is what the file directory looks like on my computer for the .htaccess file

Directory of C:\@Xoom Cargo New\@WEBV06

06/14/2013  01:20 AM                37 .htaccess
04/26/2013  07:34 PM                53 google0ed3276f9d1755b3.html
05/05/2013  07:21 PM             8,550 index-about.html
05/05/2013  07:21 PM             8,313 index-benefits.html
06/12/2013  10:14 PM            11,428 index-eng-contactus.html
06/05/2013  10:58 PM            11,543 index-eng-contactus3.html
06/02/2013  10:18 PM             9,057 index-eng-home.html
05/29/2013  11:40 PM             7,660 index-eng-payments.html
05/29/2013  10:31 PM             9,339 index-eng-privacy.html

The content of the .htaccess file looks like this

AddType application/x-httpd-php .html

The file was upload to the same directory where I have my pages and get the issue I explained before.

My hosting company DOES SUPPORT php go to this link. I have a very simply php file uploaded to their servers to show the Ip adress

http://www.xoomcargo.com/new/php/yourip.php

The code looks like this

<?php 
echo $_SERVER['REMOTE_ADDR']; 
?>

So I know PHP works on my hosting company server. BTW hostway.com one of the largest.

I am going to make a copy of the registration page and rename to .php and see what happens. To start from clean slate I will temporarily remove the .htaccess file.

Thanks for everyones patience in advance
gsam777

Member Avatar for diafol

I'd simply rename the file extension. Using the Apache fix will mean that the server may do needless processing on all plain vanilla non-php-containing html files.

My hosting company DOES SUPPORT php go to this link.

Good to hear, but your error suggested php was not able to run.

Diafol - BAM !!!! It worked. I simply renamed the file to .php published it up to the server and pulled it up and the IP address now shows up on the screen. I don't want to declare victory yet I have to get it to post to the CRM database but as far as getting it up on the screen it works.

I will now do some basic testing GO HIDDEN etc. etc. and post an update.

Stay tuned.

almostbob I still owe you an answer as to what zoho says. I already posted the question to them and they are good about getting back to me.

AS OF THIS POSTING 6/16.2013 6:26Pm E.S.T. THE .HTACCESS file is NOT UP ON THE SERVER.

Stay tuned
Gsam777

Member Avatar for diafol

Great news! So far... :)

BTW - I'm assuming this site isn't functioning yet or hasn't been. Or you'd be looking at a significant 'oops' moment.
If however it has, then some of your clients may have bookmarked your pages and with the change from .html to .php, they could be looking at an error screen - if so - this should help:

    #   backward compatibility ruleset for
    #   rewriting document.html to document.php
    #   when and only when document.php exists
    <Directory /var/www/htdocs>
        RewriteEngine on
        RewriteBase /var/www/htdocs

        RewriteCond $1.php -f
        RewriteCond $1.html !-f
        RewriteRule ^(.*).html$ $1.php
    </Directory>

(copied from http://httpd.apache.org/docs/trunk/rewrite/remapping.html )

BTW when you went to the Spanish page link it did not work because the site is under re-construction. Once I get this page working the way I want I will continue on.

Wash > Rinse > Repeat :)

gsam777

Ok after many tests and changes it all works I am able to send the IP address through the form to ZOHO. Had to tweak the snippet they generate to include the IP address on the form and after I did that I simply made it hidden. To cheat a bit I use the same REMOTE_ADDR code to plug the ip address in the Country field to make sure it was coming across while I was working with the new hidden IP address field. I figured that if the country field would show it coming across that the hidden field should work and it did.

I don't want to flag this as solved yet because I would like to hear back from zoho about what they recommend. To get at the point that ALMOSTBOB was making.

About one week ago one of my mistakes when I was renaming the form to .PHP I was add the following lines of code to the beginning and end and that was mistake.

<?php 
?>

But when Diafol simply said to rename It I did and it worked. One of my other issues is that my MS expression 3 web software tool does not work or play nice with PHP files that have a bunch of HTML code. So I have all the code in HTML and simply copy everything into the PHP version and publish it without touching it and it works. I can live with that.

ALMOSTBOB stay tuned
DIAFOL Thanks for everything so far.

Gsam777

Ok this should be the final update and the final take away.

AlmostBoB, ZOHO got back to me and their response was that they do not have any functionality at this time to record the IP address of any using their WEBTOCONTACT page functionality. So to that end I was not surprised but then again for the price one pays and the value of the software so far it is still worth it.

Diafol, no more changes other than the ones you suggested last. I tested the page from another IP address and the address came across to the other side just fine from that location.

I will leave this thread open for a couple of days before I close it out.

FINAL TAKEAWAY

  1. Renaming the page from .html to .php did the trick
  2. You DO NOT HAVE to and should not have to include the <?php and ?> in the renamed php page. This will just mess things up.

  3. The final line of code that worked for me was:

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

  4. The .htaccess file is no longer uploaded to my hosting server. I removed it.

  5. For testing I included the IP address in the country field to make sure it was coming across when needed. That line of code looked like this.

    <input style="color:#000000" type='text' maxlength='30' name='Mailing Country' style="width: 150px" value='<?php echo $_SERVER["REMOTE_ADDR"]; ?>' />

Thanks folks
Any final comments are welcome before I close this out.

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.