Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[PHP] Anti SQL Injection Script

Divine Celestial
Loyal Member
Joined
Nov 11, 2004
Messages
810
Reaction score
0
Well, to start things off, this is a modded version of one that was posted by someone else...I forgot his name, but if you search for it, I'm sure you could find it. I've added more things to it to make it more secure and reliable. Here they are:

PHP:
// Anti-SQL Injection
function check_inject()
  {
    $badchars = array(";", "'", "\"", "*", "DROP", "SELECT", "UPDATE", "DELETE", "-");
  
    foreach($_POST as $value)
    {
      if(in_array($value, $badchars))
      {
        die("SQL Injection Detected\n<br />\nIP: ".$_SERVER['REMOTE_ADDR']);
      **
      else
      {
        $check = preg_split("//", $value, -1, PREG_SPLIT_OFFSET_CAPTURE);
        foreach($check as $char)
        {
          if(in_array($char, $badchars))
          {
            die("SQL Injection Detected\n<br />\nIP: ".$_SERVER['REMOTE_ADDR']);
          **
        **
      **
    **
  **

This also works faster by a few mili seconds. This is the first of many PHP releases that I will be making to RaGEZONE. I use this very same script on the KolieMU site (soon to come). I hope you enjoy it.

[N]asser` ~ Out
 
Last edited:
Divine Celestial
Loyal Member
Joined
Nov 11, 2004
Messages
810
Reaction score
0
No problem.

[N]asser` ~ Out
 
Divine Celestial
Loyal Member
Joined
Nov 11, 2004
Messages
810
Reaction score
0
I've also newly added a new character into the array..."-". If you have this script check for injection on your stats adder, it should stop the - bug.

[N]asser` ~ Out
 
Newbie Spellweaver
Joined
Aug 18, 2004
Messages
77
Reaction score
0
I don't know why people continue using this type of anti-sql-inject, I use this:
Code:
if ((eregi("[^a-zA-Z0-9_-]", $memb___id)) || (eregi("[^a-zA-Z0-9_-]", $memb__pwd))) {
	echo("SQL Injection Detected");
**
 
Last edited:
Junior Spellweaver
Loyal Member
Joined
Dec 27, 2004
Messages
108
Reaction score
16
DataMatrix said:
I don't know why people continue using this type of anti-sql-inject, I use this:
Code:
if ((eregi("[^a-zA-Z0-9_-]", $memb___id)) || (eregi("[^a-zA-Z0-9_-]", $memb__pwd))) {
	echo("SQL Injection Detected");
**
hahhahaha hahahaha that Echo will not protect a thing :)
 
Banned
Banned
Joined
Apr 16, 2005
Messages
9
Reaction score
0
But i Didnt Understand How i put this :( Where need to do somthing?
 
Newbie Spellweaver
Joined
Aug 18, 2004
Messages
77
Reaction score
0
Hmm, it echo does the job on my server, but thanks for the tip, i'll change to die.

themad said:
hahhahaha hahahaha that Echo will not protect a thing :)

PS: Was there any need in that big gay butt laugh?
 
Divine Celestial
Loyal Member
Joined
Nov 11, 2004
Messages
810
Reaction score
0
Yea, it was fun. By the way, this script is very effective, even though very simple.

[N]asser` ~ Out
 
Divine Celestial
Loyal Member
Joined
Nov 11, 2004
Messages
810
Reaction score
0
Nemesiz said:
to protect from sql injection i think need to make check of length of login and password

Why? You know what injection is right? Here's an example...in a form that submits to your db, for example your login you put this:

Username: bob; DROP TABLE Character;

Yea, that's bascially it and that's what my script protects you against.

[N]asser` ~ Out
 
Initiate Mage
Joined
Oct 5, 2004
Messages
1
Reaction score
0
DataMatrix said:
I don't know why people continue using this type of anti-sql-inject, I use this:
Code:
if ((eregi("[^a-zA-Z0-9_-]", $memb___id)) || (eregi("[^a-zA-Z0-9_-]", $memb__pwd))) {
	echo("SQL Injection Detected");
**
don't u think u should u use exit() ?
Code:
if ((eregi("[^a-zA-Z0-9_-]", $memb___id)) || (eregi("[^a-zA-Z0-9_-]", $memb__pwd))) {
	echo("SQL Injection Detected");
        exit();
**
exit() stops the script. So after detecting sql injection script stops and nothing happens :p~
 
Newbie Spellweaver
Joined
Mar 24, 2004
Messages
30
Reaction score
0
[N]asser "bob; DROP TABLE Character;" its 26 simbols. Username max is 10 simbols. Event is player enter his name "mylonglongname" its 14 simbols. SQL insert only 10. To protect from sql injection and bugs username need to be checked using eregi("[^a-z0-9_-]", $memb___id) (is you use big letters you make a bug).
If player want to use username "drop" your $badchars = array(";", "'", "\"", "*", "DROP", "SELECT", "UPDATE", "DELETE", "-"); dont helps to him.

fancy want do you think die() do ?
 
Junior Spellweaver
Loyal Member
Joined
Dec 27, 2004
Messages
108
Reaction score
16
or just this
PHP:
if ((eregi("[^a-zA-Z0-9_-]", $memb___id)) || (eregi("[^a-zA-Z0-9_-]", $memb__pwd))) {
	die("<font color=red><b>SQL Injection Detected</font</b>");
**
 
Banned
Banned
Joined
Apr 16, 2005
Messages
9
Reaction score
0
[I REPEAT]But i Didnt Understand How i put this Where need to do somthing?
 
Divine Celestial
Loyal Member
Joined
Nov 11, 2004
Messages
810
Reaction score
0
messmaker said:
[I REPEAT]But i Didnt Understand How i put this Where need to do somthing?

Put the code I gave you in a page and save it as functions.php...Then on whichever page you want to call the script, use this:

PHP:
include_once('functions.php');
check_inject();

That's about it.

[N]asser` ~ Out
 
Banned
Banned
Joined
Apr 16, 2005
Messages
9
Reaction score
0
Quote:
Originally Posted by messmaker
[I REPEAT]But i Didnt Understand How i put this Where need to do somthing?


Put the code I gave you in a page and save it as functions.php...Then on whichever page you want to call the script, use this:

PHP Code:
include_once('functions.php');
check_inject();
But tell me I understand i put in a page with that script whit named functions Php but.... this i didn't understand
PHP Code:
include_once('functions.php');
check_inject();
 
Back
Top