Is there a way to get the IP address of someone viewing your page using PHP?
I tried searching here at sitepoint, just that your keywords have to be three letters long... so ip kinda doesn't work. Also looked through php.net, and that didn't turn up any results either.
It could be just me, but when I'm logging people going to the site everytime, using $REMOTE_ADDR I just get the local IP, ie 127.0.0.1... Perhaps kev was right, or we are both wrong?
The best way to determine what environment variables are available on your server setup is to create a page that calls the built-in function phpinfo(). The output of this function displays a list of all available environment variables, as well as all variables available from the server interface API (e.g. ISAPI or Apache). The variables available to you will be drastically reduced if you use the CGI version of PHP.
AlexC is right. $REMOTE_HOST will display the user's hostname, if Apache is set to do reverse DNS on everyone who visits. If not, then you will only see $REMOTE_ADDR which is their IP address.
In order to not concern about how the server sets this up, how do we write codes in a script to check $REMOTE_HOST or $REMOTE_ADDR or both to get the correct IP address of someone viewing your page?
Thanks in advance.
Ok, I've tried $REMOTE_HOST and $REMOTE_ADDR both locally and on my server. Both do not work. $REMOTE_HOST on both give me nothing, and $REMOTE_ADDR on both give me the local IP.
As for $HTTP_X_FORWARDED_FOR Camikaze, this gives me two IP addresses.
203.173.225.149, 203.109.252.13
From looking at mine I know the first one is mine. Where does the second one come into things. I know the second one is very similar to my ISP's server IP. Would this be the IP of the server requesting the page?
If this is true then, I can just get the string position of the comma and then select everything up to that comma using substr. However there is probably a more economical way of doing this.
Bookmarks