你好,我只是想检查一下,看看这是正确的PHP语法:
if ($input == "DeOnTRAY96@localhost"){
echo"
Projects: 1"?>
<br>
<?php
echo"
Admin: yes
";
}
elseif ($input == NULL){
die("Please enter password.");
}else{
header("Location:Invalidpassword.php");
exit;
}
就在这里写
if($input == "DeOnTRAY96@localhost"){
if($input == "DeOnTRAY96@localhost" or "somethingelse"){
还能用吗?
你不需要
if($input == "DeOnTRAY96@localhost" or "somethingelse"){
你想要的if($input == "DeOnTRAY96@localhost" or $input == "somethingelse"){
我可能建议在这种情况下使用===
而不是==
,因为您想要类型敏感的比较。
另外,对于$input == NULL
,您应该使用is_null($input)
。Null在大多数编程语言中是很奇怪的,所以用于测试的特定于语言的函数通常是一种方法(而不是比较)
PHP中的OR语法:
if($var == 'something' || $var == 'something else')
{
//do something
}
参考:
||
表示OR
&&
表示AND
对于更具前瞻性的解决方案,请考虑in_array
。我只使用两个选项,如果有一点点可能会有更多的添加。
if( in_array($input, ["DeOnTRAY96@localhost", "somethingelse"]))
一旦你有四个或更多的选项,最好这样做:
$whitelist = [
"DeOnTRAY96@localhost"
, "somethingelse"
, "anotheroption"
, "too many options to do inline!"
];
if( in_array($input, $whitelist))