You will be best off doing:
$id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
This way you can avoid function overhead is_numeric. Any of these methods is sufficient to avoid injections, though (if you are doing something for the data, if it is_numericreturns FALSE). The ternary operator also ensures that you do not get E_NOTICE if the $ _GET variable in question does not exist.
source
share