Reputation: 474
Hi new to coding and scripting, here is what I have:
<html>
<body>
<p align="left"><iframe id="aa" style="HEIGHT: 25px; WIDTH: 227px"src="http://www.html-assets.com/assets/html-building-blocks/php-display-user-ip-address.php" frameborder="0" width="600" name="aa" scrolling="no"></iframe></p>
</br><input type="text" id="ee">
<input type="checkbox" name="dd" value=" onclick="myFunction()"><em>Check the box to copy the IP Address above</em>
<script>
myFunction() {
var x = document.getElementById("aa");
var y =(x.contentWindow || x.contentDocument);
if(dd.oncheck==true){
f.ee.value = y;
}
}
</script>
</body>
</html>
What I am trying to do is have something where the page lists out the IP Address of an end-user. I want the user to have the ability to copy this address into an input field that can be added to a form that can be submitted.
How would I script this? At this point, the object in my iframe is outside my domain; is this impossible to call because of the same origin policy? I am planning on creating this using a .php within our own domain; I will adjust the code accordingly.
Upvotes: 1
Views: 555
Reputation: 6160
Yes, you will have to use a .php
file for this.
Once you have created your php file, then insert this code:
<?php
$userip = $_SERVER['REMOTE_ADDR'];
?>
<input type="text" value="" id="textbox1"/>
<input type="button" value="Click me" onClick="document.getElementById('textbox1').value = '<?php echo $userip;?>' "/>
The user's ip will be saved in the variable $userip
. Then, when the button is pressed, the textbox textbox1
will be filled with the user's ip address.
I hope this helps!
Upvotes: 1