note 90380 modified in function.explode by danbrown

From: Date: Sun, 19 Apr 2009 13:34:58 +0000
Subject: note 90380 modified in function.explode by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-153491@lists.php.net to get a copy of this message
Here's a simple script which uses explode() to check to see if an IP address is in an array (can be used as a ban-check, without needing to resort to database storage and queries). <?php function denied($one) { $denied = array( 0 => '^255.255.255.255', 1 => '^255.250', 2 => '^255.255.250' ); for ($i = 0 ; $i < sizeof($denied) ; $i++) { if (sizeof(explode($denied[$i], '^' . $one . '$')) == 2) { return true; } } return false; } if (denied($_SERVER['REMOTE_ADDR'])) { header('Location: denied.php'); } ?> --was-- Here's a simple script which uses explode() to check to see if an IP address is in an array (can be used as a ban-check, without needing to resort to database storage and queries). <?php function denied($one) { $denied = array( 0 => '255.255.255.255', 1 => '255.250', 2 => '255.255.250' ); for ($i = 0 ; $i < sizeof($denied) ; $i++) { if (sizeof(explode($denied[$i], $one)) == 2) { return true; } } return false; } if (denied($_SERVER['REMOTE_ADDR'])) { header('Location: denied.php'); } ?> http://php.net/manual/en/function.explode.php

« previous php.notes (#153491) next »