Suresh
Suresh

Reputation: 5997

HTML codes showing in viewpage HTML data

I’m a new to Codeigniter. Just using it in my project from last 2 months. I’ve a comment section in my project. Where any one can give comments. Every things are going perfect but when ever any one putting HTML content(image/videos) & then when those are showing back in the comment section… direct HTML codes are showing in the comment page rather than HTML content(image/videos).

ex: when i’m saving any “embed youtube video code” in the comment box & save that the out put comes as “raw Embed Video codes” rather than Youtube Video…..

I feel like it must be a minor thing but really can’t understand where the fault has occurring. Plz, if any body have the solution reply me back as soon as possible.

Upvotes: 1

Views: 284

Answers (3)

djFire
djFire

Reputation: 23

Couldn't one devise a system where somebody just posts the youtube link itself and through a combination of regular expressions your own system generates the object/embed code itself so there's no security risk possible?

Upvotes: 2

someoneinomaha
someoneinomaha

Reputation: 1304

I had a similar problem a while back - wanting to give end users the ability to post YouTube videos, but not allow them to just post anything without some sort of XSS protection.

I ended up using htmlpurifier - http://htmlpurifier.org/ to filter the contents being submitted in the form.

There is a modification that can be made to the whitelist that allows YouTube code through the purifier.

http://htmlpurifier.org/docs/enduser-youtube.html

So far, that's working well, but my system is still in development.

Upvotes: 1

janosrusiczki
janosrusiczki

Reputation: 1931

As a quick hack you can do htmlspecialchars_decode when displaying the comment in your view. This is very dangerous though without the use of sanitization when you receive the comment - search xss_clean on this page. You should also use strip_tags to remove all the HTML tags you don't need (everything except the video tags) prior to inserting the comment in the database.

Upvotes: 0

Related Questions