[ Index ] |
|
Code source de Serendipity 1.2 |
1 <?php 2 // 3 // +----------------------------------------------------------------------+ 4 // | PHP Version 4 | 5 // +----------------------------------------------------------------------+ 6 // | Copyright (c) 1997-2002 The PHP Group | 7 // +----------------------------------------------------------------------+ 8 // | This source file is subject to version 2.0 of the PHP license, | 9 // | that is bundled with this package in the file LICENSE, and is | 10 // | available at through the world-wide-web at | 11 // | http://www.php.net/license/2_02.txt. | 12 // | If you did not receive a copy of the PHP license and are unable to | 13 // | obtain it through the world-wide-web, please send a note to | 14 // | license@php.net so we can mail you a copy immediately. | 15 // +----------------------------------------------------------------------+ 16 // | Authors: Martin Jansen <mj@php.net> | 17 // | Guido Haeger <gh-lists@ecora.de> | 18 // +----------------------------------------------------------------------+ 19 // 20 // $Id: CheckIP.php,v 1.5 2002/08/17 09:41:24 mj Exp $ 21 22 /** 23 * Class to validate the syntax of IPv4 adresses 24 * 25 * Usage: 26 * <?php 27 * require_once "Net/CheckIP.php"; 28 * 29 * if (Net_CheckIP::check_ip("your_ip_goes_here")) { 30 * // Syntax of the IP is ok 31 * } 32 * ?> 33 * 34 * @author Martin Jansen <mj@php.net> 35 * @author Guido Haeger <gh-lists@ecora.de> 36 * @package Net_CheckIP 37 * @version 1.1 38 * @access public 39 */ 40 class Net_CheckIP 41 { 42 43 /** 44 * Validate the syntax of the given IP adress 45 * 46 * This function splits the IP address in 4 pieces 47 * (separated by ".") and checks for each piece 48 * if it's an integer value between 0 and 255. 49 * If all 4 parameters pass this test, the function 50 * returns true. 51 * 52 * @param string $ip IP adress 53 * @return bool true if syntax is valid, otherwise false 54 */ 55 function check_ip($ip) 56 { 57 $oct = explode('.', $ip); 58 if (count($oct) != 4) { 59 return false; 60 } 61 62 for ($i = 0; $i < 4; $i++) { 63 if (!is_numeric($oct[$i])) { 64 return false; 65 } 66 67 if ($oct[$i] < 0 || $oct[$i] > 255) { 68 return false; 69 } 70 } 71 72 return true; 73 } 74 } 75 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Nov 24 09:00:37 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |