php - if(isset($_GET['w'])&&$_GET['w']>=0&&$_GET['w']<=65) not working as it should

709
   if(isset($_GET['w'])&&$_GET['w']>=0&&$_GET['w']<=65)

when$_GET['w'] has a value of (for example)ccc the condition becomes true whereas it should only accepts numbers from and including0 to and including65

350

Answer

Solution:

"ccc" == 0 is true.

You should also check whether it is a number before comparing $_GET[...] parameters this way.

isnumeric() if I'm correct.

There are other tests you can use to check whether it's a decimal number. For example, you could run apreg_match('/^[0-9]+$/', $_GET['w']) == 1.

337

Answer

Solution:

If you compare a string to a number PHP will treat the string as being equal to zero, so it would be equal to zero and less than 65. You probably want to use is_integer() as well to make sure it's an integer.

989

Answer

Solution:

$_GET is "submitted" as text. If "text" is not empty, it is == 1. So your condition matches. To avoid this, first make sure you format "w" to an integer value/variable.

People are also looking for solutions to the problem: php - Return to referer (double back)

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.