Best Way To Stop Sql Injections - sql injection

Pages: 1, 2
free web hosting

Read Latest Entries..: (Post #11) by bjrn on Jun 19 2005, 02:31 PM. (Line Breaks Removed)
You can make your own checking function to strip strange characters and quotation marks, but you might as well use the excellent PEAR DB functions for just that issue. And Trap17 has PEAR installed, so you don't have to worry about that either.Just use the prepare() and execute() functions like so:CODE<things you want to do here> require_once("PEAR.php"); require_once&#... read more.
Read the FIRST post of this Topic. - Express your Opinion! Contribute Knowledge :-).

Open Discussion > CONTRIBUTE > Computers > Programming Languages > PHP Programming

Best Way To Stop Sql Injections - sql injection

Daehawk
I was wondering on tips on the best way to set up your php site if you had a game to make it where sql injection didn't work on your game.

Reply

SystemWisdom
SQL Injection occurs via an input form (like a login), where the form accepts special characters (like !@#$%^ etc..). One of the easiest/best ways to prevent such a compromise is to disallow any special characters and force users to only use alphanumeric values when supplying input via a web-form (abc...123...).
Even spaces should be considered invalid, since SQL injection involves the use of an SQL statement containing spaces to seperate keywords (select * from [table]).

Also, you should use a URL Decoding method before validating the input, that way a %20 would get converted to a space, and filtered out (as well as any other invalid encoded characters).

Doing that should thwart about 95% (if not 100%) of any SQL Injection techniques...

Reply

FaLgoR
Create some function that strips the bad chars from the $vars, like |'"@!& you know. Or use some function that already exists, stripslashes for example. But do NEVER let $vars which will be in sql functions without any kind of "preparation" or it will be easy to maniulate the database. Be careful.

Reply

karlo
QUOTE(FaLgoR @ Jun 14 2005, 01:11 AM)
Create some function that strips the bad chars from the $vars, like |'"@!& you know. Or use some function that already exists, stripslashes for example. But do NEVER let $vars which will be in sql functions without any kind of "preparation" or it will be easy to maniulate the database. Be careful.
*


is there a function in php which will let only accept alphabet letters and numbers?.

Reply

beeseven
What I do is create an array of characters that I allow (Letters, numbers, spaces and/or underscores). Then I replace all those with "", and if there's still stuff in the string (if($str != "")) then I kill the script and prompt for a new string.

Reply

serverph
might be helpful: http://www.unixwiz.net/techtips/sql-injection.html

Reply

SystemWisdom
PHP to allow only letters/numbers:

CODE


function isAlphaNumeric( $szInput )
{
   return (bool) preg_match( '/^[a-zA-Z0-9]$/', $szInput );
}


// usage:

if( isAlphaNumeric( 'mystring123' ) )
{
   // valid
}else
{
   // invalid
}



I hope that helps!

Reply

beeseven
I don't think that there's a premade function, but you can write one, it's not that hard considering there's a function that checks if something is alphanumeric.
CODE
function is_alphanum($str) {
       if(ctype_alnum($str)) {
               return true;
       } else {
               return false;
       }
}

Then you just do something like
CODE
if(is_alphanum($text)) {
       echo "Alphanumeric";
} else {
       echo "Not alphanumeric";
}

Or you could just skip the function step, but whatever.

I apologize if there's something wrong with this post, I have to connect to Trap non-graphically through my school because I can't load it on my home connection.

 

 

 


Reply

Daehawk
Thanks for all the posts. This will help me alot with things. Yeah I had wondred where this post went after I posted it cause I couldn't find it then...boom there it is. Yay. I'm gonna save everything all of you posted to a word pad document to get to faster without having to log into here when I am off working on coding my game.


Reply

rvalkass
Another suprisingly simple tehnique is to name databases and tables with random names. For example people often look for a database called forum or phpbb etc. to inject a phpBB forum. If you use weird names it can be a last line of defence if they get through the script.

Reply

Latest Entries

bjrn
You can make your own checking function to strip strange characters and quotation marks, but you might as well use the excellent PEAR DB functions for just that issue. And Trap17 has PEAR installed, so you don't have to worry about that either.

Just use the prepare() and execute() functions like so:
CODE

<things you want to do here>
require_once("PEAR.php");
require_once("DB.php");
PEAR::setErrorHandling(PEAR_ERROR_DIE, "Aaaaargh! Error: %s");
$conn = DB::connect("mysql://username:password@localhost/databasename");
$preparedstatement = $conn->prepare('INSERT INTO tablename (field1, field2, field3, field4) VALUES (?, ?, ?, ?)');
$data = array($variable1, $variable2, $variable3, $variable4);
$conn->execute($preparedstatement, $data);
}


You will obviously have to change usernames/passwords/db name and set the variables and change table and field names to whatever you are using. smile.gif

And if it's a guestbook or forum like thing you might want to do something like:
CODE
$variable=htmlspecialchars($_POST['variable'], ENT_QUOTES);
to set HTML entitys.


PEAR is a bunch of PHP packages with all sorts of handy functions. You can get more info about PEAR at pear.php.net and more about the PEAR DB package and how to use it here.


Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Pages: 1, 2
Recent Queries:-
  1. stopping mysql injection - 1.02 hr back. (1)
  2. pear db sql injection - 9.61 hr back. (1)
  3. how to stop sql injection attacks - 20.47 hr back. (1)
  4. how to stop sql injection - 34.50 hr back. (1)
  5. php stop special char - 55.45 hr back. (1)
  6. stopping sql injection with php - 69.32 hr back. (1)
  7. php is_alphanum - 91.78 hr back. (2)
  8. php stop malicious code - 97.92 hr back. (1)
  9. what is the best way to stop common injections - 102.91 hr back. (1)
  10. stop sql injection attacks - 112.93 hr back. (1)
  11. how to stop code injection in php html - 115.00 hr back. (1)
  12. stopping sql injections - 119.03 hr back. (2)
  13. stop sql injection - 119.63 hr back. (1)
  14. php class to stop injection - 124.77 hr back. (1)
Similar Topics

Keywords : stop, sql, injections, sql, injection

  1. Malicious Code Injection
    (3)
  2. Sql Injection
    How to stop people from doing this... (9)
    Does anyone know how to keep people from using SQL injection on my site, like stop them from
    commenting everything beyond the text box out?....

    1. Looking for stop, sql, injections, sql, injection

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for stop, sql, injections, sql, injection

*MORE FROM TRAP17.COM*
advertisement



Best Way To Stop Sql Injections - sql injection



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE