# Displaying IP address



## zero11 (Jul 4, 2005)

Hi,

I have seen in several websites and want to know if someone can tell me the coding. As we enter the website it says "Your IP address is .............." and it displays the IP address of the visitor.

How do we do this? Any clues ?


----------



## brendandonhu (Jul 8, 2002)

In what language?


----------



## namenotfound (Apr 30, 2005)

It helps to know what language you want to use because it's different for each language.

However, if it's PHP then this is how it would look:
<?php $_SERVER['REMOTE_ADDR']; ?>


----------



## zero11 (Jul 4, 2005)

namenotfound said:


> It helps to know what language you want to use because it's different for each language.
> 
> However, if it's PHP then this is how it would look:
> <?php $_SERVER['REMOTE_ADDR']; ?>


Thanks for the quick replies. I would prefer html. Also can the country of the visitor also be displayed.


----------



## namenotfound (Apr 30, 2005)

Well you could do it in JavaScript, that's about as close to HTML as you can get (HTML can't do it alone).

However, I don't know much JavaScript so someone else would have to answer this


----------



## brendandonhu (Jul 8, 2002)

Javascript doesn't really know your IP, this is about the closest you can get:
http://stud1.tuwien.ac.at/~e9125168/javas/jhostip.html


----------



## knight_47 (Mar 15, 2006)

How about something like this?

http://javascript.internet.com/user-details/ip-address.html


----------



## brendandonhu (Jul 8, 2002)

It isn't getting the IP address in javascript. It requires a serverside language to get the IP then sticks it in a javascript alert box.


----------



## knight_47 (Mar 15, 2006)

brendandonhu said:


> It isn't getting the IP address in javascript. It requires a serverside language to get the IP then sticks it in a javascript alert box.


What does it use other than JavaScript? The link that I provided... Sorry I assumed it was just JavaScript, because it didn't say anything else.


----------



## brendandonhu (Jul 8, 2002)

Its getting the IP in SSI, and using JavaScript to put it an alert box.


----------



## peril0us (Oct 13, 2003)

brendandonhu said:


> Its getting the IP in SSI, and using JavaScript to put it an alert box.


And its unuseful too! I tried to use it once to send the IP in a hidden field of a form but it emailed me my own IP only lol. :up:


----------



## knight_47 (Mar 15, 2006)

I found one that uses the .htaccess to ban an IP. If you know how to set that up, this should be really easy.

http://www.javascriptkit.com/howto/htaccess5.shtml

It comes hand in hand with displaying the IP if you get it to send back in a form or something. Hope that helps.


----------



## zero11 (Jul 4, 2005)

Thanks guys for the overwhelming response.

I found this one and it works, although I want to also know the country from where they are visiting.


----------



## zero11 (Jul 4, 2005)

peril0us said:


> And its unuseful too! I tried to use it once to send the IP in a hidden field of a form but it emailed me my own IP only lol. :up:


Yes it would email the IP address of the person using the form. Maybe you used it and it sent out your IP address. You should have asked your friends to use the form and see if it returns their IP address. Anyway thanks guys.


----------



## peril0us (Oct 13, 2003)

zero11 said:


> Yes it would email the IP address of the person using the form. Maybe you used it and it sent out your IP address. You should have asked your friends to use the form and see if it returns their IP address. Anyway thanks guys.


Wrong. I got over 100 emails all with my own IP in the field.


----------



## DrP (Jul 23, 2005)

If your server supports PHP:

Insert this inside the body of your page...

Your IP address is 
<? echo $_SERVER['REMOTE_ADDR']; ?>

...then save the file as .php instead of .html and upload it to the server and navigate to it.

At the bottom of my home page I have a link which displays the IP address using that.


----------

