Dynadot Aftermarket: discover domain gems worth investing in. Visit our aftermarket.

CODE: Javascript to display user's IP

Namecheap AuctionsNamecheap Auctions
Namecheap AuctionsNamecheap Auctions
Spacemail by SpaceshipSpacemail by Spaceship
Watch

111111z

Established Member
Impact
10
Another Way to Display the IP Address on a HTML Page

http://sendmyip.com/ipjava.htm

Source code for the about \/ \/ \/ \/

<script src="http://sendmyip.com/ipjs.php" </script></script>
<p><font face="Arial Narrow">Your IP is </font>
<SCRIPT LANGUAGE="JavaScript">
document.title = "Your IP is "+ip;
document.write(ip)
</script>
</p>
 
Last edited:
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Thanks handy if you use a free hosting service like goeocities :P

But I dont so I can stick with PHP :p

PJ
 
0
Close
And for anyone who wants the code for PHP....

PHP:
<?php

echo 'Your IP is: ' . $_SERVER['REMOTE_ADDR'];

?>

-or-

PHP:
<?php

echo 'Your IP is: ' . getenv('REMOTE_ADDR');

?>
 
0
Close
very simple, but very affective :)
 
0
Close
Thanks! I may use that!
 
0
Close
I do appreciate this.

Javascript is good for client execution, but PHP is taking over....

Scott said:
And for anyone who wants the code for PHP....

PHP:
<?php

echo 'Your IP is: ' . $_SERVER['REMOTE_ADDR'];

?>

-or-

PHP:
<?php

echo 'Your IP is: ' . getenv('REMOTE_ADDR');

?>

-Steve
 
0
Close
Yeah, I believe PHP has the most popular it ever has been just after its 10th Birthday and it will always get bigger I think.

The Javascript is good for peps on geocities and stuff.

PJ
 
0
Close
PHP i the best, but that javascript was very handy! :) thanks
 
0
Close
Just a note on using $_SERVER: Your server may not support that. I *always* use $HTTP_SERVER_VARS, $HTTP_POST_VARS, $HTTP_GET_VARS, etc.
 
0
Close
EKukiela101 said:
Just a note on using $_SERVER: Your server may not support that. I *always* use $HTTP_SERVER_VARS, $HTTP_POST_VARS, $HTTP_GET_VARS, etc.
this is a good point - depends on your version of php

-Steve
 
0
Close
111111z said:
http://sendmyip.com/ipjava.htm

Source code for the about \/ \/ \/ \/

<script src="http://sendmyip.com/ipjs.php" </script></script>
<p><font face="Arial Narrow">Your IP is </font>
<SCRIPT LANGUAGE="JavaScript">
document.title = "Your IP is "+ip;
document.write(ip)
</script>
</p>
thanx for the scripts.
 
0
Close
EKukiela101 said:
Just a note on using $_SERVER: Your server may not support that. I *always* use $HTTP_SERVER_VARS, $HTTP_POST_VARS, $HTTP_GET_VARS, etc.
very helpful. I knew about $_SERVER, but will learn the alternatives for when I script php for my clients! :)

Thanks
 
0
Close
$HTTP_SERVER_VARS
$HTTP_POST_VARS
$HTTP_GET_VARS
$HTTP_ENV_VARS
$HTTP_COOKIE_VARS
$HTTP_POST_FILES
$HTTP_SESSION_VARS

To use the same behavior as $_SERVER, $_POST, $_FILES, $_SESSION, $_GET, $_COOKIE, and $_ENV on older versions of PHP, you can use:

$GLOBALS['HTTP_SERVER_VARS']
$GLOBALS['HTTP_POST_VARS']
$GLOBALS['HTTP_GET_VARS']
$GLOBALS['HTTP_ENV_VARS']
$GLOBALS['HTTP_COOKIE_VARS']
$GLOBALS['HTTP_POST_FILES']
$GLOBALS['HTTP_SESSION_VARS']

The pre-defined variable list is available at:
http://us2.php.net/reserved.variables
 
0
Close
Thankx a lot for the code.
 
0
Close
Yeah nice JS script i use PHP though. :lol:
-Coolprogram
 
0
Close
Thanks for the hint on $server. I never knew that :p
 
0
Close
Scott said:
And for anyone who wants the code for PHP....

PHP:
<?php

echo 'Your IP is: ' . $_SERVER['REMOTE_ADDR'];

?>

-or-

PHP:
<?php

echo 'Your IP is: ' . getenv('REMOTE_ADDR');

?>
dosnt work always if your behind a router...
 
0
Close
0xide said:
dosnt work always if your behind a router...

It works fine if you're behind a router. It won't return the correct IP if you're behind a proxy, however neither will JS. The best you can try is $_SERVER['HTTP_X_FORWARDED_FOR'] and hope they're using a non-anonymous (transparent) proxy server.

That is unless you want to try circumventing the proxy by using a java applet.

-Scott
 
0
Close
Scott said:
It works fine if you're behind a router. It won't return the correct IP if you're behind a proxy, however neither will JS. The best you can try is $_SERVER['HTTP_X_FORWARDED_FOR'] and hope they're using a non-anonymous (transparent) proxy server.

That is unless you want to try circumventing the proxy by using a java applet.

-Scott

That is true.

Here is a function for this (off php.net)
PHP:
<?php
function getIP($ip) {

if (getenv("HTTP_CLIENT_IP")) $ip = getenv("HTTP_CLIENT_IP");
else if(getenv("HTTP_X_FORWARDED_FOR)) $ip = getenv("HTTP_X_FORWARDED_FOR");
else if(getenv("REMOTE_ADDR")) $ip = getenv("REMOTE_ADDR");
else $ip = "UNKNOWN";

return $ip;

}
?>

Just call function getIP($ip);
And set IP with $_REMOTE_ADDR;

This is the best method there really is. Unless you wish to use C++ which you can easly get the IP. (In PHP)

iNod
 
0
Close
cool thanks for that iNod!
 
0
Close
DomainEasy: flexible LTO options. Close more domain deals with financing.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back