<?

//=============================//
//                             //
//   secure VARS               //
//   secure.VARS.php           //
//   by Razvan Stanga          //
//   razvan_stanga@yahoo.com   //
//   http://www.phprebel.org   //
//                             //
//       MADE IN ROMANIA       //
//                             //
//=============================//

// free memory of unused vars

$vlist get_defined_vars ();
$klist = array ('_GET''_POST''_SERVER''_COOKIE');

foreach( 
$vlist as $name => $value ) {
       if( 
array_search ($name$klist) === FALSE ) {
           unset ($
$name);
       }
}

unset (
$vlist$klist$name$value);

//____________

function secureVARS ($var$list) {
    global 
$_VARS;

    foreach ( 
$list as $k => $v ) {

        if ( isset ( 
$var["$k"] ) ) { // if var exists, continue
            
switch ( $v ) {
                default: 
// no processing
                    
$_VARS["$k"] = $var["$k"];
                break;

                case 
"INT"// integer
                    
$_VARS["$k"] = (int) $var["$k"];
                break;

                case 
"STR"// trim string
                    
$_VARS["$k"] = trim $var["$k"] );
                break;

                case 
"STRNOHTML"// trim string, no HTML allowed
                    
$_VARS["$k"] = htmlentities trim $var["$k"] ), ENT_QUOTES );
                break;

                case 
"STRUCW"// trim string, upper case words
                    
$_VARS["$k"] = ucwords strtolower trim $var["$k"] ) ) );
                break;

                case 
"STRUCF"// trim string, upper case first word
                    
$_VARS["$k"] = ucfirst strtolower trim $var["$k"] ) ) );
                break;

                case 
"STRTOL"// trim string, lower case words
                    
$_VARS["$k"] = strtolower trim $var["$k"] ) );
                break;

                case 
"STRURLE"// trim string, url encoded
                    
$_VARS["$k"] = urlencode trim $var["$k"] ) );
                break;

                case 
"STRURLD"// trim string, url decoded
                    
$_VARS["$k"] = urldecode trim $var["$k"] ) );
                break;
            }
        } else {
            if ( 
is_numeric $k ) AND isset ( $var["$v"] ) ) { // no processing
                
$_VARS["$v"] = $var["$v"];
            }
        }
    }
}

?>