dougan1330 2013-02-01 16:50
浏览 11

如何使用Codeigniter自动添加?

I want to apply addslashes() to all the post elements got through

$this->input->post('my_var');

How can I do that ? Is there any feature like filters under wordpress for this ?

  • 写回答

1条回答 默认 最新

  • duanpan7011 2016-07-22 16:41
    关注

    I think you want something global. My idea is to edit the global post function in the codeigniter to use addslashes on everything. You can find that function in:

    /yourfolder/system/core/Input.php

    You can escape it by setting it global.

    function post($index = NULL, $xss_clean = FALSE)
        {
            // Check if a field has been provided
            if ($index === NULL AND ! empty($_POST))
            {
                $post = array();
    
                // Loop through the full _POST array and return it
                foreach (array_keys($_POST) as $key)
                {
                    $post[$key] = addslashes($this->_fetch_from_array($_POST, $key, $xss_clean));
                }
                return $post;
            }
    
            return addslashes($this->_fetch_from_array($_POST, $index, $xss_clean));
        }
    

    Although I don't really find it as good solution to modify the global functions this should do the trick in your case.

    Edit: I see that input->post already does that and you would not need to add that function additionally.

    评论

报告相同问题?