0

I have a textbox in a page call enquiry.

i want when my page loads my ip address will come automatically in that texbox... please help me..i need your suggestions as soon as possible .

Vivek Saha
  • 145
  • 1
  • 1
  • 9

2 Answers2

1

What language are you using (server-side)?

If you want to do this in PHP, here's how:

<?php
$ip = $_SERVER['REMOTE_ADDR'];
?>


<form>
<!-- other form elements here -->
<input type="text" name="ip" value="<?php if isset($ip) { echo $ip; } ?>" />
</form>

The first part gets the users IP address. The second part prints its value in the text field.

okoboko
  • 4,332
  • 8
  • 40
  • 67
0

You want your users to see their ip address in a text box?

Assuming you have to do it on the client-side, you need to use javacript. Like this (taken from How to get client's IP address using javascript only?):

<script type="application/javascript">
    function getip(json){
      alert(json.ip); // alerts the ip address
      // instead of the alert, assign the value to your text box
    }
</script>

<script type="application/javascript" src="http://jsonip.appspot.com/?callback=getip"></script>
Community
  • 1
  • 1
Gerard
  • 638
  • 4
  • 8
  • 19