best way to secure simple wysiwyg with php

后端 未结 2 1007
走了就别回头了
走了就别回头了 2021-01-12 13:12

I have added a simple wysiwyg editor in my website. (it only allows B / I / U - no more)
I currently store all content as html in my database - but it\'s simple to add

2条回答
  •  天命终不由人
    2021-01-12 13:48

    Use strip_tags(). http://php.net/manual/en/function.strip-tags.php

    string strip_tags ( string $str [, string $allowable_tags ] )

    The second parameter is a list of allowable tags; just list '' and the rest will be stripped.

    Do note that as deceze mentioned:

    This function does not modify any attributes on the tags that you allow using allowable_tags, including the style and onmouseover attributes that a mischievous user may abuse when posting text that will be shown to other users.

    So it doesn't offer full protection from malicious code by itself!

提交回复
热议问题