gathering IP addresses in form submissions

T

Tamarin

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
 
L

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;


--
 
R

Randy Webb

Lee said the following on 3/6/2007 10:20 AM:
Tamarin said:
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 :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top