WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Function that returns an IP Address if it's correct. IMPROVED!!!
Categories : PHP, Algorithms, Network Click here to Update Your Picture
J. Flor
Date : Apr 02nd 2003
Grade : 3 of 5 (graded 5 times)
Viewed : 9365
File : ipchecker-0.2.php
Images : No Images for this code example.
Search : More code by J. Flor
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

<?php
/***************************************************************************
* ipchecker.php
*
* Wed Mar 31 11:20:01 2003
* Copyright 2003 peterflor
* Author : J. Pedro Flor
* E-Mail : peterflor@yahoo.com
*
* This function check the integrity of an IPv4 number.
* Also, allow to check octet by octet after first validation.
* The result value can be a plain "string" or (for more flexibility) an array.
*
* array = [octet-1][dot-1][octet-2][dot-2][octet-3][dot-3][octet-4]
* elements = [0] [1] [2] [3] [4] [5] [6]
* ==> A.B.C.D <==
*
* (Created with Anjuta)
*
****************************************************************************/

/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/


/*
* TODO LIST
*
* First of all: correct my english and of course, correct variable names.
*
*/

// IPv4 PHP-Checker
function check_ip($ip_target) {

        $ip_target = trim ($ip_target);

        $pre_ip = array (0, ".", 0, ".", 0, ".", 0);
        
        $length = strlen ($ip_target);
        $counter = 0;
        $octet_number = 0;
        $temporal_octet = "";
        
        
        if (($length < 7) || ($length > 15)) {
                print ("Error.");
                exit;
        }
        
        while ($counter < $length) {
                if (ctype_digit ($ip_target[$counter]) == TRUE ) {
                                $temporal_octet = $temporal_octet. $ip_target[$counter];
                } else {
                        if ($ip_target[$counter] != ".") {
                                print ("Error.");
                                exit;
                        }
                        $pre_ip[$octet_number] = $temporal_octet;
                        $octet_number += 2;
                        $temporal_octet = "";
                }
                $counter++;
        }
        
        // Tips and dirty TRICKS :)
        
        // Getting Last octet
        $pre_ip[$octet_number] = $temporal_octet;

        if ((($pre_ip[0] < 1) || ($pre_ip[0] > 255)) ||        
         (($pre_ip[count($pre_ip)-1] == "") ||
                ($pre_ip[count($pre_ip)-1] == "."))) {
                print ("Error.");
                exit;
        }
        
        for ($octet_number = 2; $octet_number < 7; $octet_number+=2) {
                if ((($pre_ip[$octet_number] < 0) ||
                ($pre_ip[$octet_number] > 255)) ||
                 (($pre_ip[$octet_number] == "") ||
                 ($pre_ip[$octet_number] == "."))) {
                        print ("Error.");
                        exit;
                }
        }

        //return $pre_ip; // Array
        return $ip_target; // Plain string
}
// Calling function
check_ip("1.25.255.1");
?>



Client classes for Dictionary servers UPDATED: 2000-06-06
Categories : Network, Search, Complete Programs, PHP Classes, PHP
quick sort for associative arrays
Categories : Algorithms, Arrays, PHP
Class for sending mail with MIME attachments in multipart format using external sendmail, mimencode and zip
Categories : Email, Network, PHP, PHP Classes
Credit Card Identification and Validation Class - The credit_card class provides methods for cleaning, validating and identifying the type of credit card numbers.
Categories : PHP, PHP Classes, Credit Cards, Ecommerce, Algorithms
Create MRTG Graphic from rrd database (Need MRTG and RRDTool installed).
Categories : PHP, Network, Graphics
How to get the exit code and result of an exec() command.
Categories : PHP, Network
Boolean Keyword Interpreter
Categories : PHP, Algorithms, Search Engines
Prime number finder (Sieve of Erastothenes)
Categories : PHP, Algorithms, Math.
A recursive function to traverse a multi-dimensional array where the dimensions are not known
Categories : Arrays, PHP, Algorithms
The Porter Word Stemming Algorithm in PHP Reduces words to their base stem for search engines and indexing
Categories : Algorithms, PHP, Strings
Library of math functions to expand the functionality of PHP3. Version 1.2.1 fixes a major problem with the gcd function.
Categories : Algorithms, PHP, Math.
Dollar Serial Number Validator
Categories : PHP, Security, Algorithms
Kasskooye($path) tell you the complete size of a folder
Categories : PHP, Algorithms, Utilities, Filesystem
How to Generate a random 8 character string in php3?
Categories : PHP, Algorithms
Examines the user's computer for open Netbus (the trojan horse) port and reports the conclusion to the user.
Categories : Network, PHP
 Adam Namejko wrote : 918
Could the function not be made more simple by using regular expression matching.  I`m not the best out there, but this works I believe.

    function check_ip($ip_target)
    {
        $ip_target = trim($ip_target);
        $first_oct = `([1-9]|[1-9][0-9]|1[0-9]{0,2}|2[0-4][0-9]|25[0-5])`;
        $all_other_oct = `([0-9]|[1-9][0-9]|1[0-9]{0,2}|2[0-4][0-9]|25[0-5])`;
        $pattern = $first_oct . `\.` . $all_other_oct . `\.` . $all_other_oct . `\.` . $all_other_oct;

        if (!preg_match("/^$pattern$/", $ip_target)) {
            print(`Error.`);
            exit;
        }
        return $ip_target;
    }
 
 tomas dzurilla wrote :922
hi, 
i was trying to use the function, but on the 20th (not counting comments) line there is an undefined function "ctype_digit". what is that function? thanks. t