note 100497 added to filter.filters.flags

From: Date: Tue, 19 Oct 2010 23:42:13 +0000
Subject: note 100497 added to filter.filters.flags
Groups: php.notes 
Request: Send a blank email to php-notes+get-173290@lists.php.net to get a copy of this message
In order to filter on loopback addresses try this : <?php function FILTER_FLAG_NO_LOOPBACK_RANGE($value) { // Fails validation for the following loopback IPv4 range: 127.0.0.0/8 // This flag does not apply to IPv6 addresses return filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) ? $value : (((ip2long($value) & 0xff000000) == 0x7f000000) ? FALSE : $value); } $var = filter_var('127.0.0.1', FILTER_CALLBACK, array('options' => 'FILTER_FLAG_NO_LOOPBACK_RANGE')); // Returns FALSE $var = filter_var('74.125.19.103', FILTER_CALLBACK, array('options' => 'FILTER_FLAG_NO_LOOPBACK_RANGE')); // Returns '74.125.19.103' // To filter Private IP ranges and Loopback ranges $var = filter_var('127.0.0.1', FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE) && filter_var('127.0.0.1', FILTER_CALLBACK, array('options' => 'FILTER_FLAG_NO_LOOPBACK_RANGE')); // Returns FALSE ?> (If someone wants to write in handling for the IPv6 loopback interface at "::1" go for it.) -Gene Wood ---- Server IP: 69.147.83.197 Probable Submitter: 206.80.1.253 ---- Manual Page -- http://www.php.net/manual/en/filter.filters.flags.php Edit -- https://master.php.net/note/edit/100497 Del: integrated -- https://master.php.net/note/delete/100497/integrated Del: useless -- https://master.php.net/note/delete/100497/useless Del: bad code -- https://master.php.net/note/delete/100497/bad+code Del: spam -- https://master.php.net/note/delete/100497/spam Del: non-english -- https://master.php.net/note/delete/100497/non-english Del: in docs -- https://master.php.net/note/delete/100497/in+docs Del: other reasons-- https://master.php.net/note/delete/100497 Reject -- https://master.php.net/note/reject/100497 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#173290) next »