note 94386 added to function.gethostbyaddr

From: Date: Sun, 01 Nov 2009 15:24:19 +0000
Subject: note 94386 added to function.gethostbyaddr
Groups: php.notes 
Request: Send a blank email to php-notes+get-162322@lists.php.net to get a copy of this message
Anonymous has a good point (though I don't agree with pushing to execution to shell unless I have to. However this is a faster example (explode then loop is a little too intensive for a simple check) <?php function gethost ($ip) { //Make sure the input is not going to do anything unexpected //IPs must be in the form x.x.x.x with each x as a number if( preg_match('/^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:[.] (?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}$/', $ip) ) { $host = host $ip; return (($host ? end ( explode (' ', $host)) : $ip)); } else { return false; } } ?> Though to be honest I would use: <?php function gethost ($ip) { return ( preg_match('/^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:[.] (?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}$/', $ip) ) ? gethostbyaddr($ip) : false; } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 68.106.154.170 ---- Manual Page -- http://www.php.net/manual/en/function.gethostbyaddr.php Edit -- https://master.php.net/note/edit/94386 Del: integrated -- https://master.php.net/note/delete/94386/integrated Del: useless -- https://master.php.net/note/delete/94386/useless Del: bad code -- https://master.php.net/note/delete/94386/bad+code Del: spam -- https://master.php.net/note/delete/94386/spam Del: non-english -- https://master.php.net/note/delete/94386/non-english Del: in docs -- https://master.php.net/note/delete/94386/in+docs Del: other reasons-- https://master.php.net/note/delete/94386 Reject -- https://master.php.net/note/reject/94386 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#162322) next »