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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:44:12+00:00 2026-05-18T01:44:12+00:00

I have sanitize class that I run before anything else on every page of

  • 0

I have sanitize class that I run before anything else on every page of my site. I’m pretty sure addslashes is the same as escaping with mysql_real_escape_string heres the class.

class sanatize
{
private static $singleton;

function __construct(){

    $_CLEAN_POST = array();
    $_CLEAN_GET = array();
    $_CLEAN_REQUEST = array();

    foreach($_REQUEST as $key => $value)
    {
        $key = addslashes(trim(strip_tags($key)));
        $value = addslashes(trim(strip_tags($value)));

        $_CLEAN_REQUEST[$key] = $value;
    }
    foreach($_GET as $key => $value)
    {
        $key = addslashes(trim(strip_tags($key)));
        $value = addslashes(trim(strip_tags($value)));

        $_CLEAN_GET[$key] = $value;
    }
    foreach($_POST as $key => $value)
    {
        if(is_array($value)){
            foreach($value as $key2 => $value2){

                $key2 = addslashes(trim(strip_tags($key2)));
                $value2 = addslashes(trim(strip_tags($value2)));

                $_CLEAN_POST[$key][$key2] = $value2;
            }
        }
        else{
            $key = addslashes(trim(strip_tags($key)));
            $value = addslashes(trim(strip_tags($value)));

            $_CLEAN_POST[$key] = $value;
        }
    }
    $_POST = array();
    $_GET = array();
    $_REQUEST = array();

    $_POST = $_CLEAN_POST;
    $_GET = $_CLEAN_GET;
    $_REQUEST = $_CLEAN_REQUEST;
}
function __destruct()
{
    //echo "cleaned";
}

public static function getInstance()
{
    if(is_null(self::$singleton))
    {
        self::$singleton = new sanatize();
    }
    return self::$singleton;
}
}

and then i’ll call it using

$sanatize = sanatize::getInstance();
  • 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-18T01:44:13+00:00Added an answer on May 18, 2026 at 1:44 am

    “I’m pretty sure addslashes is the same as escaping with mysql_real_escape_string heres the class.”

    First, it’s not. mysql_real_escape_string is aware of the connection, and takes that connection’s character set into account.

    Second, you’re basically replicating the failed magic_quotes design. Not all of those fields are going into the database, so you’re doing unnecessary work. You also have to be careful never to re-escape something in a “clean” array; double-escaping is a very common problem.

    In my opinion, the simplest solution to SQL injection is prepared statements. I recommend using either PDO or mysqli.

    EDIT: Since you’re already using mysqli, you should forget about this CLEAN idea, and simply use MySQLi_STMT. mysqli::prepare gives an example of how to create and bind variables to a prepared statement. Note the ? place-holder. Also look at mysqli_stmt::bind_param.

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

Sidebar

Related Questions

I have a file that is called header (the header of my site).. I
I have a list of strings that I need to sanitize. I have a
I have a class that inherits ActiveRecordValidationBase that contains the following property: [Property] [ValidateDecimal]
I have an MVC3 site that needs to handle user posts. I am trying
I have a class that sends an Email (MailMessage) but I get the following
I have these three functions inside the same class: public function checkLogin() { if(isset($this->getSessionVal()))
I have a partial that contains this sanitize() code: <%= sanitize comment.body, :tags =>
Have a SomeLib.pro file that contains: CONFIG += debug TEMPLATE = lib TARGET =
Have a matrix report now that has Position, Hours and Wages for a location
Have you ever obfuscated your code before? Are there ever legitimate reasons to do

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.