-2

I have a short question - is code below vulnerable for sql injection in any version of PHP?

$A = $_GET['A'];
$B = 10;
$q = "SELECT 1 FROM user WHERE name = 'admin' LIMIT ".($A*$B).",$B";
$res = mysql_query($q);
...

I saw that kind of code on my client website and got me to think... but couldn't find any attack vector :)

Elen
  • 95
  • 7

1 Answers1

-2

This is SQL safe, as the variable $A is being multiplied by an integer $B. However, all GET variables store string values, so it would be smart to typecast $A to an integer, like so:

$A = intval($_GET['A']);

OR

$A = (int) $_GET['A'];

You should also switch to the method mysqli_query(), as mysql_query() is deprecated.

Kaleb W
  • 122
  • 7