Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

in php can an sql injection possibly make it through is_numeric function?

Tags:

php

mysql

could i safely assume (if i'm just GETting an id number) that is_numeric is good enough to thwart sql injection attacks? or is there sql injection methods that can pass through is_numeric?

like image 948
Emery King Avatar asked Jan 02 '12 21:01

Emery King


2 Answers

You'd be better served to just do:

$id = isset($_GET['id']) ? (int) $_GET['id'] : 0;

This way you can avoid the is_numeric function overhead. Either method is sufficient to avoid injection, though (as long as you do something to the data if is_numeric returns FALSE). The ternary operator also makes sure you don't get an E_NOTICE if the $_GET variable in question doesn't exist.

like image 89
rdlowrey Avatar answered Oct 13 '22 01:10

rdlowrey


No, there isn't. However, remind, that for example is_numeric('0xaf5') == true, thus its maybe not enough according what you want to achieve.

like image 44
KingCrunch Avatar answered Oct 12 '22 23:10

KingCrunch