Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: sanatise code

  1. #1
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts

    sanatise code

    Just thought I'd post this one. I've always used the second part of this code since I can remember but threw errors when dealing with radio and check boxes in forms so thought it may help some folk.


    PHP Code:
    function filter$data ) {
            if( 
    is_array$data ) ) {
                foreach( 
    $data as $data_ ) {
                    
    $data_ trimhtmlentitiesmb_convert_encoding$data_'HTML-ENTITIES'"UTF-8") ) ); 
                    if ( 
    get_magic_quotes_gpc() )
                        
    $data_ stripslashes$data_ ); 
                    
    $data_ mysql_real_escape_string$data_ ); 
                    
    $_data[] = $data_;
                }
                return 
    $_data;
            }else{
                
    $data trimhtmlentitiesmb_convert_encoding$data'HTML-ENTITIES'"UTF-8") ) ); 
                if ( 
    get_magic_quotes_gpc() )
                    
    $data stripslashes$data ); 
                
    $data mysql_real_escape_string$data ); 
                return 
    $data;
            }
        } 
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 

  • #2
    eak
    eak is offline
    Regular Coder eak's Avatar
    Join Date
    Jun 2002
    Location
    Nashville, TN
    Posts
    354
    Thanks
    0
    Thanked 26 Times in 26 Posts
    That can probably be shorted with a little bit of recursion.

    To give you an idea of what I mean, this is from my DB class.
    PHP Code:
        public function escape( &$item ){
            if( 
    is_array$item ) ){
                foreach( 
    $item as $key => $i )
                    
    $this->escape$item$key ] );
            } else {
                if( 
    get_magic_quotes_gpc() )$item stripslashes$item );
                
    $item mysql_real_escape_string$item$this->dbConn );
            }
            return 
    $item;
        } 
    eak | "Doing a good deed is like wetting your pants; every one can see the results, but only you can feel the warmth."


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •