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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:28:37+00:00 2026-05-27T08:28:37+00:00

I created two simple functions to filter inserted data before it’s entered into a

  • 0

I created two simple functions to filter inserted data before it’s entered into a mysql query.

For formfields (I am also using regular expressions to check each field individually.

// Form filter
function filter($var) 
{               

    // HTML is not allowed
    $var = strip_tags(trim($var)); 

    // Check magic quotes and stripslashes
    if(get_magic_quotes_gpc())
    { 
        $var = stripslashes($var);
}

    // Not using it right now, is it recommended?
    // $var = htmlentities($var, ENT_QUOTES);

    // Escape
    $var = mysql_real_escape_string($var);

    // Return    
    return $var; 
}

Then for id’s (sent in the URL) I am using this filter:

// ID filter
function idfilter($idfilter)
{
// Delete everything except numbers
$idfilter = ereg_replace("[^0-9]", "", $idfilter);

// Round numbers
$idfilter = round($idfilter);

// Test if the input is indeed a number
if(!is_numeric($idfilter) || $idfilter % 1 != 0)
{
    $idfilter = 0;
}

// Filter using the formfilter (above)
return filter($idfilter);
} 

Are there suggestions to add or strip from these simple functions? And is it “safe”?

  • 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-27T08:28:38+00:00Added an answer on May 27, 2026 at 8:28 am

    You’re using deprecated function as magic_quotes and ereg_*. To prevent Sql injection you should use prepared statement (I suggest to use PDO) and to prevent XSS you should use strip_tags() as you’re doing.

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

Sidebar

Related Questions

I created two simple functions which get template parameters and an empty struct defining
I created two very simple Heroku apps to test out the service, but it's
Unfortunately, my question is not as simple as keeping track of two windows created
I've created a simple iPhone app which has two .xib files. In the app
I've created two functions to load expanded views of a month in the archive
I've created two simple testpages. One loads the other one using XMLHttpRequest. (just a
I created a simple window with two buttons, the first one calls a function
I have two simple functions to set and clear cookie. private function _setCookie($value =
I've created simple string class with some extra functions - its mainly for learning
Using the Stack Overflow public data dump, I've created three simple tables: Questions (Question_Id,

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.