Please contact (802) 224 - 6525 for price quotes and programming support.
Follow this link for a resume of php and Mysql Programing experience
Digg This!

0 Members and 1 Guest are viewing this topic. « previous next »

Pages: [1] Go Down Print
Author Topic: Filtering Function  (Read 2192 times)
John Anderson
Vermont Internet Design Admin
Administrator
Full Member
*****

Karma: 0
Offline Offline

Gender: Male
Posts: 238



View Profile WWW
« on: January 30, 2009, 04:05:56 PM »

  Here is a filtering function that will help clean out your inputs so they do not do any damage to your database.


Code:
1  class security_class{
2       // Prevents Buffer Overflow
3       private function size_input($data, $length = 50){
4                $out = substr($data, 0 , $length);
5                return $out;
6       }
7       // Escape Quotes and chars
8       private function escape_quotes($data){
9               $out = addslashes($data);
10               return $out;
11      }
12       // Convert to html entities
13      private function html_ent($data, $type = 'ENT_QUOTES'){
14              $out = htmlentities($data);
15               return $out;
16      }
17      //strip specified unwated chars
18      private function strip_unwanted($data, $chars = '', $replacement = ' '){
19           $chars_array =  explode("", $chars);
20           foreach($chars_array as $c_key => $c_val){
21               eval("$data = eregi_replace($c_val, $replacement, $data);");
22           }
23           return $data;
24      }
25      public function clean_data($data, $size, $escape, $esctype, $htmlent, $htmltype, $unwanted, $replacement){
26         if($size)
27             $data = $this->size_input($data);
28        
29         if($escape)
30              $data = $this->escape_quotes($data, $esctype);
31        
32         if($htmlent)
33               $data = $this->html_ent($data, $htmltype);
34         if($unwanted)
35               $data = $this->html_ent($data, $unwanted, $replacement);
36      }
37 
38 
39 }
Logged

Pages: [1] Go Up Print 
« previous next »
Jump to:  

Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC
TinyPortal v0.9.8 © Bloc
Christmas2006 design by Bloc
Page created in 0.351 seconds with 29 queries.