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 7247897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:04:01+00:00 2026-05-28T22:04:01+00:00

Possible Duplicate: What are the best practices for avoiding xss attacks in a PHP

  • 0

Possible Duplicate:
What are the best practices for avoiding xss attacks in a PHP site

I have a <textarea> and an <input> for comments of my site.Obviously, I echo them in an interface page and inserting into my database.

I want to know what do I have to do, when a person injects (for example) a <img> to damage the page or sending a query to damage database?

What is a simple way?

I’ve tried to search < > ' " drop using but although I used \" instead of " but it doesn’t work and in PHP, I’ve got error.

Is searching these characters manually the best way (PHP and Javascript)?

  • 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-05-28T22:04:02+00:00Added an answer on May 28, 2026 at 10:04 pm

    What you are trying to acheive is to prevent a form of XSS (Cross site scripting attacks) attacks. You are trying to prevent the persistent variety:

    The persistent (or stored) XSS vulnerability is a more devastating
    variant of a cross-site scripting flaw: it occurs when the data
    provided by the attacker is saved by the server, and then permanently
    displayed on “normal” pages returned to other users in the course of
    regular browsing, without proper HTML escaping. A classic example of
    this is with online message boards where users are allowed to post
    HTML formatted messages for other users to read.

    There are numerous options to prevent them. OWASP has a neat explanation.. Go through it and find out. But mostly its a very big problem for an Individual to handle solely.

    The best way is to use HTMLPurifier which is both simple and easy. It may be a bit slow. But the extra processing is worth it. To give you an example of how simple it is to use here is a basic code:

    <?php
        require_once '/path/to/htmlpurifier/library/HTMLPurifier.auto.php';
    
        $config = HTMLPurifier_Config::createDefault();
        $purifier = new HTMLPurifier($config);
        $clean_html = $purifier->purify($dirty_html);
    ?>
    

    PS: HTMLPurifier has options to “whitelist”. Use that for your advantage.

    For example, you can fine tune allowed elements and attributes,
    convert relative URLs to absolute ones, and even autoparagraph input
    text! These are, respectively, %HTML.Allowed, %URI.MakeAbsolute and
    %URI.Base, and %AutoFormat.AutoParagraph. The %Namespace.Directive
    naming convention translates to:

    $config->set('Namespace.Directive', $value);
    

    E.g.

    $config->set('HTML.Allowed', 'p,b,a[href],i');
    $config->set('URI.Base', 'http://www.example.com');
    $config->set('URI.MakeAbsolute', true);
    $config->set('AutoFormat.AutoParagraph', true);
    

    EDIT:

    To answer your question on stopping malformed SQL Injection attacks refer to this question: How can I prevent SQL injection in PHP? and this answer

    Quote:

    Use prepared statements and parameterized queries. These are SQL statements that sent to and parsed by the database server separately from any parameters.
    
    If you use PDO you can work with prepared statements like this:
    
    $preparedStatement = $db->prepare('SELECT * FROM employees WHERE name = :name');
    
    $preparedStatement->execute(array(':name' => $name));
    
    $rows = $preparedStatement->fetchAll();
    where $db is a PDO object, see the PDO documentation. The mysqli class also provides parameterized queries.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: What are the best practices for avoid xss attacks in a PHP
Possible Duplicate: Best way to stop SQL Injection in PHP I have seen some
Possible Duplicate: Best practices in error reporting (Mathematica) Assume that I have a function
Possible Duplicate: Daylight saving time and Timezone best practices Basically I have the following
Possible Duplicate: Best practice: Import mySQL file in PHP; split queries How to import
Possible Duplicate: Best way to stop SQL Injection in PHP I am creating a
Possible Duplicate: Best practices regarding equals: to overload or not to overload? Does anyone
Possible Duplicate: Best Way to Sprite Images? Hi i have been using this http://spritegen.website-performance.org
Possible Duplicate: Best way to detect integer overflow in C/C++ i have tried to
Possible Duplicate: What are best practices that you use when writing Objective-C and Cocoa?

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.