开发者

How to avoid script alert in codeigniter

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜