CodeIgniter , Filter, Trim, Stripslashes, Strip_tags and sanatize and replace bad chars in 1 function?

11,771

I suggest you read the Chapter on security on the manual, you'll see some function (mainly the XSS filterin) which do (more or less) something of what you are after - I don't think there's a function that close to yours, though. You can always write your own implentation around (or instead of) it, place the function in an helper, and have it available whenever you want.

Usually it's not applied by default, because it's quite resource-draining; you can, though, set to use it always in your config file, or on a per-post basis by passing TRUE as the second argument of $this->input-post()

If you want to go into the details of the implementation, just open the Security.php file located in system/core/, to see all the operations the xss_clean() function performs on the input provided (it's around line 264).

As for the trimming, I'm not sure it's done (I haven't checked thoroughly), but you it's pretty short to write by hand, and morever it's one of the filters available in the form validation library in case you're going to use it after a form submission.

Share:
11,771
Xees
Author by

Xees

A Web developer in saudi arabia, specializing in all things open-source. Founder of Naizk. http://www.naizk.sa

Updated on September 15, 2022

Comments

  • Xees
    Xees over 1 year

    I just started using codeigniter, and i would like to perform input formatting using 1 function.

    Code i would like implemeneted on my input:

    function sanitize ($string)
    {
        $string = filter_var($string, FILTER_SANITIZE_STRING);
        $string = trim($string);
        $string = stripslashes($string);
        $string = strip_tags($string);
    
        return $string;
    }
    

    My Question is:

    Does codeigniter perform these actions by default when i use the input class? Or do i need to create a custom function to filter my input.

    My Goal is:

    Clean and secure user input on forms and trim spaces in it.