SQL PHP HTML ASP JavaScript articles and free scripts to download If you are facing any problem in viewing this page, please tell us
 

SQL security to prevent attacks


Here are some sample codes to be used on different situations to prevent hacking. SQL vulnerability issues are not discussed here but we will be adding them shortly.

In PHP if some variables are taken from query string and used inside one mysql query then the variables are to be sanitized ( checked ) first before using.

When we don't expect any thing other than a numeric value then why not to check the variable by using is_numeric PHP function and terminate the program if data is not a number. Here is a sample code for this.
$cat_id=$_GET['cat_id'];
if(!is_numeric($cat_id)){
echo "Data Error";
exit;
}

$start=$_GET['start'];
if(strlen($start) > 0 and !is_numeric($start)){
echo "Data Error";
exit;
}


If we expect only alphanumeric characters then we can use ctype_alnum function.

if(!ctype_alnum($var)){
echo "Data Error";
exit;
}


lija14-07-2009
its very use full
pdemmy24-08-2009
the resources here are useful...thanhs
DEE02-03-2010
Well its really gud.......but it should b more comprehensive.
Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked
Sections
PHP
JavaScript
ASP
HTML
SQL
Photoshop
Articles SEO
SQL Tutorial List
SQL Commands
SQL Sections
Date & Time
Join Table
String
Math
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.