简体   繁体   English

PHP 的 _GET 不支持 if()

[英]PHP's _GET doesn't support if()

I'm using the following code:我正在使用以下代码:

if(isset($_GET['TDEnderEmail']) || htmlspecialchars($_GET['TDEnderEmail'])){
  $VEENFSL = strval($_GET['TDEnderEmail']);
  if(strpos($VEENFSL, "@enderadel.cf") > 0 && strlen($VEENFSL) > 5 && strlen($VEENFSL) < 22){
    return true;
  }
}

and although that $VEENFSL 's if (strpos($VEENFSL, "@enderadel.cf") > 0 && strlen($VEENFSL) > 5 && strlen($VEENFSL) < 22 ) statements values are turn for the example - user@enderadel.cf - if() never return a true尽管$VEENFSLif (strpos($VEENFSL, "@enderadel.cf") > 0 && strlen($VEENFSL) > 5 && strlen($VEENFSL) < 22 ) 语句值在示例中轮流 - user@enderadel.cf - if()从不返回 true

Be warned that strpos doesn't work like you probably think it does: as the documentation states, strposstrpos不像您认为的那样工作:正如文档所述, strpos

Returns the position of where the needle exists relative to the beginning of the haystack string (independent of offset).返回针相对于 haystack 字符串开头的位置(与偏移量无关)。 Also note that string positions start at 0, and not 1.另请注意,字符串位置从 0 开始,而不是 1。

Returns FALSE if the needle was not found.如果未找到针,则返回 FALSE。

Warning This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE.警告 此函数可能返回布尔值 FALSE,但也可能返回计算结果为 FALSE 的非布尔值。 Please read the section on Booleans for more information.请阅读有关布尔值的部分以获取更多信息。 Use the === operator for testing the return value of this function.使用 === 运算符来测试此函数的返回值。

This means that your example string probably matches at position 0, therefore这意味着您的示例字符串可能在位置 0 处匹配,因此

strpos($VEENFSL, "@enderadel.cf") > 0

is false .false

Therefore, you should replace that with因此,您应该将其替换为

strpos($VEENFSL, "@enderadel.cf") !== false

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM