Forum Moderators: coopster

Message Too Old, No Replies

REMOTE ADDR=1295:b508:4161:b4bf:316f:ab00:a00:0

How can I get '200.12.55.20' format?

         

guarriman

11:14 am on Jun 7, 2007 (gmt 0)

10+ Year Member



Hi.

Using PHP v4.4.4 on Apache 2.2, I'm trying to get the IP address of each visitor. To do it, I use $_REMOTE_ADDR, but I get this info:
1295:b508:4161:b4bf:316f:ab00:a00:0

How can I show remoteAddress in '200.12.55.20' format?

Thank you very much.

dreamcatcher

11:30 am on Jun 7, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$_SERVER['REMOTE_ADDR'];

dc

guarriman

2:40 pm on Jun 7, 2007 (gmt 0)

10+ Year Member



code:

$remoteAddress = $_SERVER['REMOTE_ADDR'];
echo "$remoteAddress\n";

output:


1295:b508:4161:b4bf:316f:ab00:a00:0

(sorry, I wrote $_REMOTE_ADDR by mistake in the first post)

Scally_Ally

4:15 pm on Jun 7, 2007 (gmt 0)

10+ Year Member



does this output any different?

$ret = apache_getenv("REMOTE_ADDR");
echo $ret;

doubt it will but maybe worth a go..

[edited by: Scally_Ally at 4:15 pm (utc) on June 7, 2007]

Philosopher

4:32 pm on Jun 7, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm no expert, but that sure looks like an IPv6 address, in which case, you won't get it into the IPv4 structure as they are quite different.

coopster

11:32 pm on Jun 7, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You could write your own class based on RFC2373 (well originally, but it's been updated by RFC4291 [rfc-editor.org]) or you might want to check into a PEAR class. You could use the whole class or peel out the parts you need, such as splitv64 [pear.php.net].

guarriman

2:55 pm on Jun 8, 2007 (gmt 0)

10+ Year Member



apache_getenv("REMOTE_ADDR") doesn't work for me :(