Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP显示用户名或密码反馈消息_Php_If Statement_Message_Feedback - Fatal编程技术网

使用PHP显示用户名或密码反馈消息

使用PHP显示用户名或密码反馈消息,php,if-statement,message,feedback,Php,If Statement,Message,Feedback,当输入无效的用户名或密码时,我需要显示消息 我已经设置好了它,这样当发生什么事情时,它会将页面重定向回index.php页面,但添加了?message=Bad\u Username或?message=Bad\u Password 我还设置了一个if语句,以便在满足某些条件时,可以在用户名或密码字段下方打印消息 我只是不确定If语句的条件是什么,它才能工作 这是密码 if($\u GET['username'])){ echo“此用户名无效”; if(标题(“location:index.php?

当输入无效的用户名或密码时,我需要显示消息

我已经设置好了它,这样当发生什么事情时,它会将页面重定向回
index.php
页面,但添加了
?message=Bad\u Username
?message=Bad\u Password

我还设置了一个if语句,以便在满足某些条件时,可以在用户名或密码字段下方打印消息

我只是不确定If语句的条件是什么,它才能工作

这是密码

if($\u GET['username'])){
echo“

此用户名无效”

; if(标题(“location:index.php?message=Bad_Username”)){ echo“

此用户名无效”

; } }
如果您在get中收到一些信息,则表示用户名不正确。如果您没有收到任何信息,则表示用户尚未尝试连接

只需在您的登录页面(您有表单的地方)中执行此操作:


登录页面和登录处理分为两个文件

如果您在get中收到一些信息,则表示用户名不正确。如果您没有收到任何信息,则表示用户尚未尝试连接

只需在您的登录页面(您有表单的地方)中执行此操作:


登录页面和登录处理分为两个文件

$\u GET
只是一个数组。知道了这一点,就可以检查键和特定值是否存在<代码>如果(isset($\u GET['message'])和&$\u GET['message']=='Bad\u Username'){…
如果(header
…完全没有意义。根据,
header()
不返回值,因此如果对
进行求值,则没有什么用处。即使它返回了值,也不清楚您试图通过这样的语句来实现什么。设置重定向头会告诉浏览器忽略当前响应而转到另一个页面。因此,在当前响应中回显某些内容是没有意义的nse,因为您刚刚告诉浏览器忽略它。
$\u GET
只是一个数组。知道这一点,您可以检查键和特定值的存在。
if(isset($\u GET['message'])&&$\u GET['message']=='Bad_Username'){…
if(header
…毫无意义。根据,
header()
不返回值,因此如果对
进行求值,则没有什么用处。即使它返回了值,也不清楚您试图通过这样的语句来实现什么。设置重定向头会告诉浏览器忽略当前响应而转到另一个页面。因此,在当前响应中回显某些内容是没有意义的nse,因为您刚刚告诉浏览器忽略它。
if ($_GET['message']==Bad_UserName) {
        echo "<p class='help is-danger'>This username is invalid</p>";
    }
if ($_GET['message']==Both_Bad) {
    echo "<p class='help is-danger'>This username and password 
          are invalid</p>";
}
if ($_GET['message']==Bad_Username) {
    echo "<p class='help is-danger'>This username is invalid</p>";
}
if ($_GET['message']==Bad_Password) {
    echo "<p class='help is-danger'>This password is invalid</p>";
}
$user="user1"; //user example
$pass="1234"; //pass example

//method post or get (depends on your form method)
$inputUser = filter_var($_POST['user'], FILTER_SANITIZE_STRING);
$inputPass = filter_var($_POST['pass'], FILTER_SANITIZE_STRING);

if($inputUser!=$user && $inputPass!=$pass){
    header("location: index.php?message=Both_Bad");
}elseif ($inputUser!=$user) {
    header("location: index.php?message=Bad_Username");
}elseif ($inputPass!=$pass) {
    header("location: index.php?message=Bad_Password");
}else{
    $_SESSION['user'] = $inputUser //can be the login, id of the user or something else
    header("location: MyNextPage.php");
}