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

  • Home
  • SEARCH
  • 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 8359735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:14:38+00:00 2026-06-09T11:14:38+00:00

Possible Duplicate: What's the best method for sanitizing user input with PHP? What are

  • 0

Possible Duplicate:
What's the best method for sanitizing user input with PHP?
What are the best PHP input sanitizing functions?
The ultimate clean/secure function

Goal: Properly sanitize all inputs from text boxes before entering into DB, which is then output to a page. For my use case, I need to prevent potential problems while not eliminating the data input. Also, the charset is explicitly set to UTF-8 in both the HTTP header and the META tag to prevent problems with malformed encoding. The DB is also set to UTF-8.

Specs: PHP, MySQL, Apache

Sample Code:

    function secureinput($input)
    {
       $input = htmlspecialchars($input, ENT_QUOTES ,'UTF-8');
       $input = strip_tags($input); //fail-safe for anything that gets through
       $input = mysql_real_escape_string($input);

       return $input;
    }

Question: What vectors of attack (XSS, SQL Injection, etc.) is this still vulnerable to?

A huge thanks to anyone who can help. This is my first time posting, though I’ve always turned to SO first for looking up answers to my questions. Unfortunately, this time I couldn’t find any other questions that answered my problem, only small parts of it.

  • 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-09T11:14:39+00:00Added an answer on June 9, 2026 at 11:14 am

    XSS Attacks

    By using htmlspecialchars() whenever you output user-inputted content, you can ensure you will be safe from XSS attacks.

    SQL Injection

    Steve Friedl provides some examples of SQL Injections and limitations of input sanitization on his website: http://www.unixwiz.net/techtips/sql-injection.html

    Even though your code may be secure from SQL injection attacks with mysql_real_escape_string(), you are better off using parameterized SQL and eliminating the risk of SQL injection altogether. You will also be much more secure if you use PDO or mysqli in PHP instead of the deprecated mysql functions.

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

Sidebar

Related Questions

Possible Duplicate: What's the best method for sanitizing user input with PHP? I'm using
Possible Duplicate: What is the best method to merge two PHP objects? I have
Possible Duplicate: The best overloaded method match for 'XDevkit.IXboxDebugTarget.GetMemory(uint, uint, byte[], out uint)' has
Possible Duplicate: Best way to stop SQL Injection in PHP I am creating a
Possible Duplicate: Best way to stop SQL Injection in PHP I have seen some
Possible Duplicate: Best practice: Import mySQL file in PHP; split queries How to import
Possible Duplicate: Best XML Parser for PHP Using JAXB with Google Android I need
Possible Duplicate: What function to use to hash passwords in MySQL? Secure password storage
Possible Duplicate: Best practices in error reporting (Mathematica) Assume that I have a function
Possible Duplicate: Best way to use PHP to encrypt and decrypt? I am new

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.