Skip to content
Advertisement

PHP is_int is not performing as expected

I have a page (index.php) that takes a GET variable from the URL and checks it for security purposes. This GET variable should only be an integer. I am using the following code to check this, but in all instances, integer or not, I get the index.php page. The header never appears. After this code, the rest of the page appears starting with the html tag.

PHP:

<?php ob_start(); session_start();
$q=trim($_GET['q']);
if (!is_numeric($q)){
header("HTTP/1.0 404 Not Found");
}
?>

Advertisement

Answer

It won’t be an integer if it’s passed in a query string.

Try is_numeric()

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement