SQL Injection -measures for prevention

Reply

Join Date: Sep 2009
Posts: 13
Reputation: ultras1 is an unknown quantity at this point 
Solved Threads: 0
ultras1 ultras1 is offline Offline
Newbie Poster

SQL Injection -measures for prevention

 
0
  #1
Oct 21st, 2009
Hi, I'm making litle CMS with PHP+Mysql. Can you tellme measures for prevention for SQL Injections ?
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 72
Reputation: smartness is an unknown quantity at this point 
Solved Threads: 10
smartness's Avatar
smartness smartness is offline Offline
Junior Poster in Training
 
0
  #2
Oct 23rd, 2009
--> mysql_real_escape_string

--> Use htmlentities() for user submitted data!

when you get the id from the url:
$id = $_GET["id"];
use this:
$id = (int)$_GET["id"];

this is only when the ID is a integer!

I would suggest using a php mysql class!
Last edited by smartness; Oct 23rd, 2009 at 2:54 pm.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 62
Reputation: kylegetson is an unknown quantity at this point 
Solved Threads: 9
kylegetson's Avatar
kylegetson kylegetson is offline Offline
Junior Poster in Training
 
1
  #3
Oct 24th, 2009
using php base64_encode and php base64_decode can help as well.

never run a query on data you unsure about.

also, its a good idea to restrict the permissions of the mysql user your scripts are using, so in case someone does get in, they can't create, alter or drop tables. require an additional login before allowing those type of queries.

backup early. backup often.
Don't pay data charges. txtFeeder.com is a free way to read the web on your mobile, and avoid data charges! **Now txtFeeder has a wireless note feature! Make notes on the go!
-Kyle Getson
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 13
Reputation: ultras1 is an unknown quantity at this point 
Solved Threads: 0
ultras1 ultras1 is offline Offline
Newbie Poster
 
0
  #4
Oct 24th, 2009
Originally Posted by smartness View Post
when you get the id from the url:
$id = $_GET["id"];
use this:
$id = (int)$_GET["id"];

this is only when the ID is a integer!
Interesting

Originally Posted by kylegetson View Post
using php base64_encode and php base64_decode can help as well.
I had never known about that, it looks interesting. For example if I have "index.php?id=33&page=1" . What to encode? I guess "id=33&page=1" ?
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 62
Reputation: kylegetson is an unknown quantity at this point 
Solved Threads: 9
kylegetson's Avatar
kylegetson kylegetson is offline Offline
Junior Poster in Training
 
0
  #5
Oct 24th, 2009
When creating links use:
  1. $id=33;
  2. $page=1;
  3. $link = "index.php?id=".base64_encode($id)."&page=".base64_encode($page);

Then when getting those variables:
  1. $id = base64_decode($_GET['id']);
  2. $page = base64_decode($_GET['page']);

hope that helps.
Don't pay data charges. txtFeeder.com is a free way to read the web on your mobile, and avoid data charges! **Now txtFeeder has a wireless note feature! Make notes on the go!
-Kyle Getson
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 190
Reputation: mwasif is an unknown quantity at this point 
Solved Threads: 25
mwasif mwasif is offline Offline
Junior Poster
 
0
  #6
34 Days Ago
There is a simple rule, always treat user input an evil
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 2
Reputation: koldex is an unknown quantity at this point 
Solved Threads: 0
koldex koldex is offline Offline
Newbie Poster
 
0
  #7
34 Days Ago
Good
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the MySQL Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC