EasyPHPScripts.com      Free Open Source PHP Scripts and Code Snippet Library

 +Menu
+   Site News
+   Main Pages
+   Other Downloads
 +PHP
+ Arrays (9)
+ Array Map recursive
+ Change Calculator
+ Change Case
+ Count Array Values
+ Dump Highlighted
+ Input Validation
+ Neddle in Haystack
+ Print Nice
+ ScanTree
+ Directory And Files (7)
+ Image (3)
+ LDAP (3)
+ MySQL (11)
+ Other (11)
+ Regular Expressions (3)
+ String Manipulation (13)
+ Time and Date (6)
 +Snippet Options
+   Printer Friendly
 +Library Options
+   View Other Library
 +General Options
+   Log in
Description for Snippet: Arrays / Input Validation
  Just edit a bit in the head of the file.
upload and include into files.
 
Syntax for: Input Validation

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
<?php

//function clean_int($input)
//known $_GET int values
$CLEAN['INT'] = 'id,edit,delete,add';

//post_htmlentities(strip_slashes(clean_string_input($value)))
$CLEAN['POST_ENTITIES'] = 'Message,Subject,Notes';

/** Line 64
clean_string_input($value); , admin access = access('1',$_SESSION['Group'])
      elseif(in_array($val,array($CLEAN['POST_SKIP'])) & access('1',$_SESSION['Group'])) $val = clean_string_input($val);
*/
$CLEAN['POST_SKIP'] = 'savecontent';

//function clean_post($v)
$CLEAN['POST'] = array('document.',"\\",'<','>','`',':',';','{','}','[',']');

/**

function to clean all crap from differnt OS's, via copy paste.
$r=TRUE replaces with know chars. 
$r=FALSE replaces with nothing, removes them all
clean_string_input($input,$r=TRUE)

*/

  
function clean_input($input) {
    return 
eregi_replace("[^A-Z,0-9,_\-\. ]"''clean_string_input($input));
  }

  function 
clean_int($input) {
          return 
eregi_replace("[^0-9]"''$input);
  }
  
  function 
clean_post($v){
      global 
$CLEAN;
      if(
is_numeric($v) || is_bool($v)) return($v);
      if(
is_array($v))
        return 
array_map_r('clean_post',$v);
      
//$with = array();
      
$v str_ireplace($CLEAN['POST'],''$v);
      
$v trim($v);
      return 
$v;
  }

    function 
clean_gets($val){
       global 
$CLEAN;
       if(
is_numeric($val) || is_bool($val)) return($val);
      
$val url_decode($val);
       if(
is_array($val))
          return 
array_map_r('clean_gets',$val);
      if(
in_array($val,array($CLEAN['INT']))) $val clean_int(clean_string_input($val));
      else 
$val clean_post(strip_slashes(clean_string_input($val)));
      return(
$val);
    }
    
    function 
clean_posts($val){
       global 
$CLEAN;
      if(
is_numeric($val) || is_bool($val)) return($val);
       if(
is_array($val))
          return 
array_map_r('clean_posts',$val);
      if(
in_array($val,array($CLEAN['POST_ENTITIES']))) $val post_htmlentities(strip_slashes(clean_string_input($val)));
      elseif(
in_array($val,array($CLEAN['POST_SKIP']))) $val clean_string_input($val);
      else
        
$val clean_post(strip_slashes(clean_string_input($val)));
      return(
$val);
    }


    function 
strip_slashes$string ){
       if(
is_numeric($string) || is_bool($string)) return($string);
      if (
is_array($string))
          return 
array_map_r('strip_slashes'$string);
       return 
stripslashes($string);
    }

    function 
add_slashes$string ){
       if(
is_numeric($string) || is_bool($string)) return($string);
       if (
is_array($string))
          return 
array_map_r('add_slashes'$string);
      return 
addslashes($string);
    }
    
    function 
url_decode$string ){
       if(
is_numeric($string) || is_bool($string)) return($string);
      if (
is_array($string))
          return 
array_map_r('url_decode'$string);
      return 
urldecode($string);
    }

    
/**
    array_map_r('function', array());
    or
    array_map_r(array('class', 'method'), array());
    */
    
function array_map_r$func$arr ){
      if(!
is_array($arr)){
        return(
$func($arr));
      } else {
        
$newArr = array();
        
//print_r2($arr);
        
foreach( $arr as $key => $value ){
          
$newArr[$key] = ( is_array$value ) ? array_map_r$func$value ) : ( is_array($func) ? call_user_func_array($func$value) : $func$value ) ) );
        }
        return 
$newArr;
      }
    }
  

    
// "encode"
     //([^\x09\x0A\x0D\x20-\x7F]|[\x21-\x2F]|[\x3A-\x40]|[\x5B-\x60])
    /**
    $chars_array = array(32=>47,58=>60,62=>63,91=>94,96=>96,123=>255);
    $chars = '';
    foreach($chars_array as $idx => $val){      
      //$chars_r .= $idx.' '.$val.'| ';
      $chars .= '[\x'.strtoupper(dechex($idx)).'-\x'.strtoupper(dechex($val)).']|';
    }
    $chars = rtrim($chars,'|'); 
     echo $chars.'<br>'."\r\n";
    */ 

  
function post_htmlentities($string) {
      if (
is_array($string)){
          return 
array_map_r('post_htmlentities'$string);
      }
    
$string htmlspecialchars_decode(html_entity_decode("{$string}"));
    return 
preg_replace(
    
'/([^\x60\x2F\x5C\x5E\x20-\xFF]|[\x20-\x26]|[\x28-\x2B]|[\x3A-\x3C]|[\x3E-\x3F]|[\x7B-\x95]|[\x98-\xBF0])/e'
            
'"&#".ord("$0").";"'"{$string}");
  }
  
  function 
get_htmlentities($string) {
      if (
is_array($string)){
          return 
array_map_r('get_htmlentities'$string);
      }

    
$string htmlspecialchars_decode(html_entity_decode("{$string}"));
    return 
preg_replace(
    
'/([^\x60\x2F\x5C\x5E\x20-\xFF]|[\x20-\x26]|[\x28-\x2B]|[\x3A-\x3C]|[\x3E-\x3F]|[\x7B-\x95]|[\x98-\xBF0])/e'
            
'"&#".ord("$0").";"'"{$string}");
  }
  
  function 
clean_string_input($input,$r=TRUE){
    if(!
defined('CR')) define('CR',"\r\n");
      if (
is_array($string)){
          return 
array_map('clean_string_input'$string);
      }
    
$search = array(
    
'/[\x82\x91\x92\xb4\xb8]/i'// single quotes
    
'/[\x84\x93\x94]/i',             // double quotes
    
'/[\x85]/i',                     // ellipsis ...
    
'/[\x01-\x08\x0c\x0e-\x1f\x7f\x8f\x90]/i' // all other non-ascii
    
);
    if(
$r)
    
$replace = array(
    
"'",
    
'"',
    
'...',
    
"\r\n"
    
);
    else
    
$replace = array(
    
'',
    
'',
    
'',
    
''
    
);
    return 
preg_replace($search,$replace,$input);
  }
  
  
if(
$_GET){
    
$_GET clean_gets($_GET);
}
if(
$_POST){
    
$_POST clean_posts($_POST);
}

?>
 


 
Powered by: PHP & centOS