Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8396957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:40:13+00:00 2026-06-09T20:40:13+00:00

I am working on a comment system in Codeigniter and would appreciate some advice

  • 0

I am working on a comment system in Codeigniter and would appreciate some advice on what kind of validation rules that I should employ. I don’t want to allow any images or other any HTML.

So far I just have trim and max_length set. I also run the content through htmlspecialchars before I insert in the database. I have XSS filtering enabled globally.

What other precautions should I take? Is htmlspecialchars enough for preventing Javascript or other malicious code from being entered?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T20:40:14+00:00Added an answer on June 9, 2026 at 8:40 pm

    You should probably do a regular form validation on required and max_length, and obviously xss filtering before pushing things to the database. The htmlspecialchars should only be applied to characters that aren’t in tags, so you can’t just do htmlspecialchars directly. You need to:

    1 – strip the tag elements (and store them) like “<br/>” or “<b>“, but not their content, that means nothing inside the “<b>” and “</b>“. You can probably do this with a preg_match.

    2 – execute htmlentities on all the remaining text

    3 – remove all unwanted explicit tags (from the stored bunch of tags)

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

    4 – then filter the allowed tags for attributes and content. It’s not uncommon for hackers to use code like

    <b onMouseOver="window.open(..)"></b>
    

    To fix this, either you’ll have to do a little bit of extra work and probably work with some regex-es. If you want me to write some more sample code let me know.

    6 – re-add the tag elements back to the document.

    I just basically cooked this up right now. The algorithm can be improved in efficiency (i.e. strip the unwanted tags first, and then proceed with filtering html entities and tag contents) but I’ll leave that up to you.

    This is as far as I can see the potential hacks right now. There might be other ways to hack your input though, so you might want to check what other comment box systems out there use for their validation, such as the phpbb forum system. Another option might be to use the phpbb square-bracket format to deal with tags so you don’t let users input ANY html tags whatsoever, but instead use square-bracket tags that you control.

    Does this answer your question ?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a comment voting system. I have a page profile_new.php?id=194 That
I'm working on a PHP comment system and came across the problem that the
I am making an inline comment reply system It's mostly working except that I
I'm working on a system that requires high file I/O performance (with C#). Basically,
OK - so am working on a system that uses a custom datepicker control
Anyone know how to create a threaded / nested comment system? I would like
I am working on a comment system on a social network, I am using
I am working on a comment system and design is my weak area, So
I had following script for comment system working nicely until I put parameters into
I'm working on a commenting system that uses Markdown and I want to have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.