Free web development scripts for the webmasterDevelopment Scripts


 
 Site Navigation
 o Development Scripts
 o Text Only Edition
 o PHP.net News
 o Tutorials
 o Register an account
 o New entries this week
 o Affiliates/Links
 o Contact Us
 o About us
 o Advanced Search

 Browse Path

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /usr/local/psa/home/vhosts/devscripts.net/httpdocs/online.php on line 28
 o  users online
 o Most users online: 67
 o Home
  o PHP
   o Tips and Hints
    o Script

 Member Login
User Name
Password

 Standards
Valid XHTML 1.0!
Valid 
CSS!

 Recommended Links
 o PHP Freaks
 o Designer Baby Clothes
 o Advertise Here Make Money
 o OxyScripts
 o designplace
 o Wedding Vendor Directory
 o Send Invoices for Free
 o Free Wedding Websites
 o Free Online Invoices
 o UK Business Franchises

Protection Against SQL Injection Attacks (Rated 5)

Description:

SQL Injection attacks are ways of extracting, or modifying your database without appropriate permissions.

These two functions can help you to make your scripts a little more secure.

First Function:
The majority of injection attacks require the user of single quotes to terminate an expression. By using a simple replace function and converting all single quotes to two single quotes, you're greatly reducing the chance of an injection attack succeeding.

Second Function:
Another way of exploiting scripts is to use certain characters and character sequences such as ;, --, select, insert and xp_. By removing these characters and character sequences from user input before we build a query, we can help reduce the chance of an injection attack even further.

Code starts here


<?PHP

function stripQuotes($strWords)
{
$strWords = str_replace("''", "'", $strWords)
return
$strWords ;
}

function
killChars($strWords)
{
$badChars = array("select", "drop", ";", "--", "insert", "delete", "xp_") ;

str_replace() ;
foreach(
$badChars as $current)
{
$strWords = str_replace($current, '', $strWords);
}

return
$strWords ;
}

?>


Submitted by Devscripts on 30-06-2003 13:38


Rate This Script

User Contributed Comments

On 01-07-2003 18:34 darkobjects said:

nice script, i had no clue about sql injection attacks.


On 06-08-2010 16:55 said:

7sJdkp lvcvhsdfavwx, [url=http://buamtwucvkhk.com/]buamtwucvkhk[/url], [link=http://pbnujoliswlj.com/]pbnujoliswlj[/link], http://kryfrwzgrsof.com/


On 10-08-2010 4:51 said:

HI56fG hplvpaiibeij, [url=http://swmqykcodcje.com/]swmqykcodcje[/url], [link=http://fehqucmojwjd.com/]fehqucmojwjd[/link], http://ftmlmmpbkdjz.com/


Registered Members login
© Copyright 2003 - Devscripts.net