isset 解析错误? [PHP]
Parse Error on isset? [PHP]
我对 HTTP/PHP 编码还很陌生,在 PHP 中使用 isset
遇到了一些麻烦。
这是我当前的代码,它应该检查用户名和密码是否是 Admin 和 Password,如果是,它会回显一些信息。
然而,它不起作用。没有错误,它只接受所有用户名和密码。
$username = isset($_POST['password']);
$password = isset($_POST['username']);
$date = date('d-m-y');
$time = date('h:m:s');
$day = date('l');
if($username == 'Admin' and $password == 'Password')
{ //echo bla bla bla..
isset
只是检查是否设置了变量。另一方面,您的用户案例需要检查实际值:
if(isset($_POST['username']) and
$_POST['username'] == 'Admin' and
isset($_POST['password']) and
$_POST['password'] == 'Password') {
// echo...
为了像现在一样使用在变量中传递的 isset()
,您需要使用三元运算符。
即:
$username = isset($_POST['password']) ? $_POST['password'] : "default";
试试这个,
if(isset($_POST['password']) && isset($_POST['username'])){
$username = $_POST['password'];
$password = $_POST['username'];
$date = date('d-m-y');
$time = date('h:m:s');
$day = date('l');
// code here
if($username == 'Admin' and $password == 'Password'){
// Okay
}else{
// not Okay
}
} else {
// error
}
您可以在 php isset 中阅读 isset 的用法,其中 isset 的值似乎为 true 或 false 。所以变量 $username 的值是 true 或 false ,变量 $password 也是如此。因此,如果您要检查 POST 操作的值,您可以使用
if(isset($_POST['username']) && isset($_POST['password'])){
$username = $_POST['username'];
$password = $_POST['password'];
$date = date('d-m-y');
$time = date('h:m:s');
$day = date('l');
if($username == "Admin" && $password == "Password")
{ //echo bla bla bla..
}
}
我对 HTTP/PHP 编码还很陌生,在 PHP 中使用 isset
遇到了一些麻烦。
这是我当前的代码,它应该检查用户名和密码是否是 Admin 和 Password,如果是,它会回显一些信息。
然而,它不起作用。没有错误,它只接受所有用户名和密码。
$username = isset($_POST['password']);
$password = isset($_POST['username']);
$date = date('d-m-y');
$time = date('h:m:s');
$day = date('l');
if($username == 'Admin' and $password == 'Password')
{ //echo bla bla bla..
isset
只是检查是否设置了变量。另一方面,您的用户案例需要检查实际值:
if(isset($_POST['username']) and
$_POST['username'] == 'Admin' and
isset($_POST['password']) and
$_POST['password'] == 'Password') {
// echo...
为了像现在一样使用在变量中传递的 isset()
,您需要使用三元运算符。
即:
$username = isset($_POST['password']) ? $_POST['password'] : "default";
试试这个,
if(isset($_POST['password']) && isset($_POST['username'])){
$username = $_POST['password'];
$password = $_POST['username'];
$date = date('d-m-y');
$time = date('h:m:s');
$day = date('l');
// code here
if($username == 'Admin' and $password == 'Password'){
// Okay
}else{
// not Okay
}
} else {
// error
}
您可以在 php isset 中阅读 isset 的用法,其中 isset 的值似乎为 true 或 false 。所以变量 $username 的值是 true 或 false ,变量 $password 也是如此。因此,如果您要检查 POST 操作的值,您可以使用
if(isset($_POST['username']) && isset($_POST['password'])){
$username = $_POST['username'];
$password = $_POST['password'];
$date = date('d-m-y');
$time = date('h:m:s');
$day = date('l');
if($username == "Admin" && $password == "Password")
{ //echo bla bla bla..
}
}