Ignore:
Timestamp:
Feb 24, 2024 6:31:54 AM (3 months ago)
Author:
anonymous
Message:

Minor improvements. Add Validator::IPAddress() method.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Validator.inc.php

    r799 r807  
    520520    *
    521521    * @param  string $form_name The input data to validate.
    522     * @param  const  $type  A LOG_* constant (see App->logMsg())
    523     * @param  string $file  Filename to log (usually __FILE__)
    524     * @param  int    $line  Line number to log (usually __LINE__)
    525     * @return bool   True if no errors found, false otherwise.
     522    * @param  const  $type      A LOG_* constant (see App->logMsg())
     523    * @param  string $file      Filename to log (usually __FILE__)
     524    * @param  int    $line      Line number to log (usually __LINE__)
     525    * @return bool              True if no errors found, false otherwise.
    526526    */
    527527    static public function fileUploaded($form_name, $type=LOG_DEBUG, $file=null, $line=null)
     
    555555    *
    556556    * @access   public
    557     * @param    string $form_name The input data to validate.
    558     * @param  const  $type  A LOG_* constant (see App->logMsg())
    559     * @param  string $file  Filename to log (usually __FILE__)
    560     * @param  int    $line  Line number to log (usually __LINE__)
    561     * @return   bool   True if no errors found, false otherwise.
     557    * @param    const  $type  A LOG_* constant (see App->logMsg())
     558    * @param    string $file  Filename to log (usually __FILE__)
     559    * @param    int    $line  Line number to log (usually __LINE__)
     560    * @return   bool          True if no errors found, false otherwise.
    562561    * @author   Quinn Comendant <quinn@strangecode.com>
    563562    * @version  1.0
    564563    * @since    20 Aug 2014 14:44:23
    565564    */
    566     static public function fileUploadSize($form_name, $type=LOG_DEBUG, $file=null, $line=null)
     565    static public function fileUploadSize($type=LOG_DEBUG, $file=null, $line=null)
    567566    {
    568567        $app =& App::getInstance();
     
    575574    }
    576575
     576    /*
     577    *
     578    *
     579    * @access   public
     580    * @param
     581    * @return
     582    * @author   Quinn Comendant <quinn@strangecode.com>
     583    * @since    09 Feb 2024 21:03:57
     584    */
     585    public static function IPAddress($val, $flags=null, $type=LOG_DEBUG, $file=null, $line=null)
     586    {
     587        $app =& App::getInstance();
     588        if (is_string($val) && '' === trim($val)) {
     589            // Don't be too bothered about empty strings.
     590            return true;
     591        }
     592
     593        if (!filter_var($val, FILTER_VALIDATE_IP, $flags)) {
     594            $app->logMsg(sprintf('%s (line %s) failed: %s', __METHOD__, __LINE__, getDump($val)), $type, $file, $line);
     595            return false;
     596        } else {
     597            return true;
     598        }
     599    }
     600
    577601} // THE END
    578602
Note: See TracChangeset for help on using the changeset viewer.