Jump to content

Filter class


waynew

Recommended Posts

I have a filter class. Looking for pointers. Do any of you guys see a problem? Or have a suggestion? Simple stuff I know, but I'd like to iron this class out and make sure that it's fine. I haven't had a chance to actually test the last two functions.

 

<?php

/*
    FOR DATA CLEANING, SECURE OUTPUT AND HANDLING OF POSSIBLE MAGIC QUOTES
*/

class Filter{

    function input($string){
        $string = $this->magic_quotes_check($string);
        $string = mysql_real_escape_string($string);
        return $string;
    }
    
    function magic_quotes_check($string){
        if(get_magic_quotes_gpc() == 1){
            $string = stripslashes($string);
        }
        return $string;
    }
    
    function output($string){
        $string = htmlentities($string,ENT_QUOTES,"utf-8");
        return $string;
    }
    
    function clean_post(){
        if(count($_POST) > 0){
            foreach($_POST as $key => $value){
                $_POST[$key] = $this->input($_POST[$key]);
            }
        }
        return $_POST;
    }
    
    function clean_get(){
        if(count($_GET) > 0){
            foreach($_GET as $key => $value){
                $_GET[$key] = $this->input($_GET[$key]);
            }
        }
        return $_GET;
    }
}
?>

Link to comment
https://forums.phpfreaks.com/topic/141941-filter-class/
Share on other sites

I don't know if I would ever put a magic_quotes handler in a class. To me that is one of those things that should be done when the application starts, like being part of a global include file. The reason I say that, is because it's not something that an application should use more than one time. So to me it's part of the initialization process that comes before any class inheritances! A registry class that defines input rules (cast of type, minimum / maximum ranges if int, string or html, floats, ...) is great, but magic quotes is one of those things I believe should be done before anything else.

Link to comment
https://forums.phpfreaks.com/topic/141941-filter-class/#findComment-743232
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.