WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
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 Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
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
Submit Site
Forex Trading Online forex trading platform

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 : 6943
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 
 

<?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");
?>



Check parameters validity. Paranoia was designed to check the validity of the parameters that a php page will receive after a form submission. It can be used to check the variables sent by POST or GET
Categories : Algorithms, HTML and PHP, PHP, Variables
A very simple way to build and do a hierarchical html categories browser without javascript , just using html php and mySql
Categories : HTML and PHP, Databases, Algorithms, PHP, MySQL
Password Creator: This PHP code exmaple shows how to use bitwise operations on a single variable and using it as a flagged variable. The class generates passwords of a given length using specified characters and the flags.
Categories : PHP, PHP Classes, Algorithms, Security
PHP Function to Encrypt/Decrypt a string without a known key. The string itself has his own different key for every character.
Categories : PHP, Algorithms, Security, Authentication, Encryption
Class for sending mail with MIME attachments in multipart format using external sendmail, mimencode and zip
Categories : Email, Network, PHP, PHP Classes
Boolean Keyword Interpreter
Categories : PHP, Algorithms, Search Engines
PHP4 HTTP Compression Speeds up the Web
Categories : PHP, Zlib, HTML and PHP, HTTP, Network
WebServerSpy checks which kind of Webserver is running, Apache, Netscape, Fasttrack, IIS, HTTP-Header, HTTP 1.0, GET, spy, WWW
Categories : HTTP, Network, Apache, PHP, Web Servers
Browse a MySQL database & draw a tree view & load final items into a template page.
Categories : MySQL, Complete Programs, Algorithms, PHP, Databases
Recursive function to move files on a filesystem. It can be minor changed in order to copy recursively.
Categories : PHP, Filesystem, Algorithms
Examines the user's computer for open Netbus (the trojan horse) port and reports the conclusion to the user.
Categories : Network, PHP
Mail-lib provides a simple interface to the sendmail program. Note: you must actually have sendmail on your machine (sorry windows NT users).
Categories : Algorithms, Email, PHP
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
SHA: Implementation of the Secure Hash Algorithm in pure PHP. This is a secure one-way function that can be used to perform challenge response login algorithms over an insecure connection.
Categories : Algorithms, PHP, Security
 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