开发者

How to avoid script alert in codeigniter

开发者 https://www.devze.com 2023-03-02 02:38 出处:网络
I want to avoid script alert in my view page.That is when i users add script in text box or test area ,this script should display as script in my site\'s view page.

I want to avoid script alert in my view page.That is when i users add script in text box or test area ,this script should display as script in my site's view page.

For example,

If user enter a message in text area like alert('hai');, this should display as alert('hai');. But now its 开发者_开发百科alert hai in alert box, when the view page is opened .


To stop this from happening use the native php function 'strip_tags'

$stripped = strip_tags($content);

Do this before you echo the data from the database.

Alternatively, if you want the tag to remain but without it being parsed use something like str_replace or preg_replace:

$stripped = str_replace("<", "&lt;", $content);

Or better yet: htmlspecialchars()

etc.

0

精彩评论

暂无评论...
验证码 换一张
取 消