我有一个包含用户付费模块的字符串。如果模块不是字符串的一部分,则应显示错误页面。
变量
$paidModules
包含reminder newsfeed system finance
这是 PHP 部分,我在其中检查用户是否为该模块付费。如果不是这种情况,则应显示
noAccess.php
页面。
if($paidModules != null & $paidModules != "" ) {
if (strpos($paidModules,'reminder') == false) {
include('noAccess.php');
return;
}
}
现在的问题是,即使变量
$paidModules
包含reminder
,noAccess.php
也会显示出来。我做错了什么?
来自 PHP 手册
This function may return Boolean FALSE, but may also return a
non-Boolean value which evaluates to FALSE.
Please read the section on Booleans for more information.
Use the === operator for testing the return value of this function.
您想使用
===
进行等同
strpos($paidModules,'reminder') === false
检查是否完全错误,这样就不会得到字符串位置 0:
if (strpos($paidModules,'reminder') === false) {