Clean input from user

Page 1 of 1

3 Replies - 894 Views - Last Post: 15 January 2015 - 06:48 PM

#1 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1659
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Clean input from user

Posted 24 February 2009 - 09:25 AM

Description: This is a function I use for cleaning all input provided from the end user
<?php
//Function for cleaning all input from the end user
function clean_input($user_input)
{
   $user_input = trim($user_input);
   
   //check to see if magic quotes are turned on
   if(get_magic_quotes_gpc())
   {
      //clean the user's inpt using stringspashes to
      //unquote a quoted string
      $user_input = stripslashes($user_input);
   }
   
   //check for numeric values, if not
   //clean it
   if(!is_numeric($user_input))
   {
        $user_input = mysql_real_escape_string($user_input);
   }
   return($user_input);
} 
?>

		


Is This A Good Question/Topic? 0
  • +

Replies To: Clean input from user

#2 SpaceMan  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 10
  • View blog
  • Posts: 507
  • Joined: 20-February 03

Re: Clean input from user

Posted 11 April 2009 - 05:09 PM

this good for mysql, if you have a live DB connection. wont work if you are not logged into the MySQL server. so would be "Clean MySQL Inputs"
Was This Post Helpful? 0
  • +
  • -

#3 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1659
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Clean input from user

Posted 11 April 2009 - 08:33 PM

Well if you're not inputting the user into a database why would you need to clean it?
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101  Icon User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12186
  • View blog
  • Posts: 45,250
  • Joined: 27-December 08

Re: Clean input from user

Posted 15 January 2015 - 06:48 PM

Note that using prepared statements should eliminate the need for this snippet.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1