Question


I want to check of there is a ean code (only numeric) in the $_GET method. And of check of that is a number. When it is not of that two i want to redirect to another page, and exit the php script.

if(!isset($_GET["ean"])){
    header('Location: /products.php');  
    exit();
}else{
    if(is_nan($_GET["ean"])){
        header('Location: /products.php');
        exit();
    }
}

When $_GET["ean"] = 234234sd (So, it is not numeric) there is a php error:
Notice: A non well formed numeric value encountered in ..... on line 9
Line 9 is the line with de is_nan function.

Thanks,

Was it helpful?

Solution

In, PHP NaN is a float. See the docs: http://www.php.net/manual/en/language.types.float.php#language.types.float.nan

Because of this, is_nan wants a float as a parameter. It will tell you whether it's NaN or not.

In your case, you want is_numeric.

if(!is_numeric($_GET["ean"])){
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top