note 40554 added to function.gethostbyaddr

From: Date: Sun, 07 Mar 2004 21:34:34 +0000
Subject: note 40554 added to function.gethostbyaddr
Groups: php.notes 
Request: Send a blank email to php-notes+get-66405@lists.php.net to get a copy of this message
in reply to: info at widebore dot com about the only thing that is present in the REMOTE_ADDR variable is IP's, and they're seperated by a comma. (the only exception is "unknown", which is placed there if a user is behind a proxy that does not show the http_x_forwarded_for) so while you solution is a good one (the @ in front of the function) you could (very easily) go thru that variable and parse it. <?php $remote = $_SERVER["REMOTE_ADDR"]; if (strstr($remote, ","){ $remote_array = explode(",", $remote); foreach ($remote_array as $ip){ $hostname_array = @gethostbyaddr($ip); } }else{ $hostname = @gethostbyaddr($remote); } ?> also, the *real* IP should be the last IP in remote_addr; so you could do as in the above example but only get the IP of the last in the array (<?php $hostname = @gethostbyaddr(end($remote_array)); ?>) ps: all code is untested ---- Manual Page -- http://www.php.net/manual/en/function.gethostbyaddr.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+40554 Delete -- http://master.php.net/manage/user-notes.php?action=delete+40554&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+40554&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#66405) next »