473,395 Members | 1,637 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

gathering IP addresses in form submissions

Hello,

I'm an HTML coder, and am learning how to integrate JS and PHP into form
functions.

I'm trying to engineer a form that will return the user's IP address as a
hidden input field.

I found a code snippet to capture the visitor's IP as such:

==================
<SCRIPT>
var ip = new java.net.InetAddress.getLocalHost();
var ipStr = new java.lang.String(ip);
document.writeln(ipStr.substring(ipStr.indexOf("/")+1));
</SCRIPT>
========================

and I tried to use the variable (both as "ip" and as "ipStr"), but with the
resulting form return yeilding "undefined".

my hidden field is generated by a Document.write statement as such:

===========================
<script type="text/javascript">
document.write ('<input type="hidden" name="ip_number" value="' + ipStr +
'">');
</script>
===========================

thanks for any help in solving this!

Tam
Mar 6 '07 #1
2 3240
Lee
Tamarin said:
>
Hello,

I'm an HTML coder, and am learning how to integrate JS and PHP into form
functions.

I'm trying to engineer a form that will return the user's IP address as a
hidden input field.

I found a code snippet to capture the visitor's IP as such:

==================
<SCRIPT>
var ip = new java.net.InetAddress.getLocalHost();
var ipStr = new java.lang.String(ip);
document.writeln(ipStr.substring(ipStr.indexOf( "/")+1));
</SCRIPT>
========================
That will only work in a few browsers, and what it will tell you
is the IP address that my PC uses in my local network. Unless
you're working on a company intranet, it's not useful to you.
There are thousands of other people using the same IP address.

Your PHP code on the server side already knows what it thinks
my IP address is, anyway. That's a different IP from what my
browser would tell you, and just about as useless. Depending
on which computer I use, it may be an address that changes
every time I log in, or it may be a proxy address that I share
with many other people.
>my hidden field is generated by a Document.write statement
Don't do that. Create the hidden field in normal HTML and
simply use javascript to set its value:

document.forms["myFormName"].elements["ip_number"].value=ipStr;
--

Mar 6 '07 #2
Lee said the following on 3/6/2007 10:20 AM:
Tamarin said:
<snip>
>my hidden field is generated by a Document.write statement

Don't do that. Create the hidden field in normal HTML and
simply use javascript to set its value:

document.forms["myFormName"].elements["ip_number"].value=ipStr;
Or, let PHP generate it with the IP Address it thinks is right and then
the form can get submitted and PHP can think the client gave it to them :-)

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 6 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Steve Holden | last post by:
Dear Python User: We have received many enquiries asking "When and how will I be able to submit my paper to PyCon DC 2004?". This is encouraging news - from the correspondence to date it seems...
3
by: Mark Michel | last post by:
Hi. I have made an html form which I would like to send by e-mail. When the recipient receives the e-mail form, I would like them to be able to fill it out and click the Submit button which will...
6
by: nick4soup | last post by:
I have read the CGI FAQ 'How can I avoid users hitting "submit" twice' (on http://www.htmlhelp.org/faq/cgifaq.3.html#19 ) which essentially says you have to detect it at the server, using a...
5
by: bissatch | last post by:
Hi, I have been trying to come up with an idea to reduce double submissions where a user clicks refresh and, for example, another row is INSERT into a table. Originally, I would have a form...
4
by: Diane Selby | last post by:
Hi- I am developing an ASP.NET application that can take a few seconds to process the request from the user. We are looking for a client-side solution that will prevent users from resubmitting...
0
by: Toby Inkster | last post by:
Like me, you are probably confronted with many requests for surveys, questionnaires, feedback forms, registration forms and so forth: forms where the processing requirements are very simple (store...
15
by: Rainman | last post by:
In the following simplified tag: <a href='mailto:<address1@somewhere.com>,<address2@nowhere.com>?subject=Testing'> click here</a> When clicked, both addresses appear as "To:" recipients when...
4
by: kschneider | last post by:
Assume there's a form with it's action attribute all set to post to a URL, but without a submit control. Form submission is done via a link and I want to prevent the classic "double submit"....
14
by: Ed Jay | last post by:
Despite searching the net, I can't find a suitable solution that prevents a user's double click from submitting a form twice. I'm currently using the following in a button element: <input...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.