Jump to content

Check your IP

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
6 replies to this topic

#1
Guest_Jaan_*

Guest_Jaan_*
  • Guests
<html>

<head>

<script language="JavaScript">

function disp_ip(){

var ip = '<!--#echo var="REMOTE_ADDR"-->';

document.write(ip)

}

</script>

</head>

<body>

<form>

<input type='button' value='Check your Ip' onClick='disp_ip();'>

</form>

</body>

</html>

But you have to use .shtml extension not .html or .htm because it uses server side includes :)

#2
DevilsCharm

DevilsCharm

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 884 posts
Always good to have alternatives to ipchicken, ha ha.

#3
chili5

chili5

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 7,247 posts
Interesting, the only thing is your server has to have SSI enabled for this to work.

Is their anyway to do this if SSI isn't enabled? I do have SSI enabled but I'm just curious.

#4
v0id

v0id

    Retired

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,936 posts
Yes, you'll need to have SSI enabled in order to use the SSI functionality. Most servers does have it as default though, so normally you don't have to mess with it.

#5
chili5

chili5

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 7,247 posts
My server I needed to enable SSI first but it was possible.

Though looking at the code, I don't think you need the javascript do you?

Couldn't you just do this:


<html>

<head>

</head>

<body>

<!--#echo var="REMOTE_ADDR"-->

</body>

</html>


but on my computer, when testing it, the IP that is displayed is 127.0.0.1 which isn't my IP. :o

#6
v0id

v0id

    Retired

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,936 posts
It's true that you don't need Javascript at all, but the advantage of using Javascript in this situation is that you can save the result in a variable, and eventually use it for various string operations.

About your IP: If you ran the script locally, it will most likely return localhost (127.0.0.1).

#7
chili5

chili5

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 7,247 posts
Yeah I guess that is true, you could edit the string without reloading the page, so I guess it is a good idea to use JavaScript here.