Getting the client’s IP address using JavaScript
September 20, 2008
Filed under
Development, JavaScript
This will be a serious disappointment: simply it’s not possible. Javascript is not designed to access this detail of the clients.
I find this thing very odd, because while it’s possible to get the CPU type, the screen height and width and many other details of the client, we can’t get the IP of the client.
So we need other way to do it. Here comes in help server side scripting, basically you define the javascript variable using a server side script, like this:
var clientip = <?php echo $_SERVER['REMOTE_ADDR']; ?> /*OR*/ var clientip = <?= $_SERVER['REMOTE_ADDR'] ?>
Other server side code is also welcomed, it doesn’t matter whether you use PHP or ASP, the fact that you can’t use JS matters only…
So, world saved again… partially
Possible related posts (automatic):
Related posts brought to you by Yet Another Related Posts Plugin.



















Comments
Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!
If you want to use your OpenID, fill out the field labeled "Website" with the OpenID URL. The other fields may remain empty.