Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.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_Login - Fatal编程技术网

如何在没有弹出框的情况下显示php登录错误消息

如何在没有弹出框的情况下显示php登录错误消息,php,login,Php,Login,当有人输入错误的用户名或密码时,我希望在页面上显示错误消息。现在它使用一个弹出框来显示消息,但我希望它出现在页面上。我该怎么做呢?下面是我的php <?php if(!defined("SESSION")){ session_start(); define("SESSION", true); } if(isset($_GET["log_out"])){ unset($_SESSION["logged_in"]); header('re

当有人输入错误的用户名或密码时,我希望在页面上显示错误消息。现在它使用一个弹出框来显示消息,但我希望它出现在页面上。我该怎么做呢?下面是我的php

<?php
    if(!defined("SESSION")){
       session_start();
       define("SESSION", true);
 }
 if(isset($_GET["log_out"])){
    unset($_SESSION["logged_in"]);
    header('refresh: 0; url=login.php'); 
    exit;
 }

 $login = true;
 require "protect.php";

 $logins[0]["user"] = "";
 $logins[0]["pass"] = "";
 $logins[0]["redirect"] = "test.php";

 $logins[1]["user"] = "";
 $logins[1]["pass"] = "";
 $logins[1]["redirect"] = "";

 $logins[2]["user"] = "";
 $logins[2]["pass"] = "";
 $logins[2]["redirect"] = "test.php";

 // No need to edit below, except the errors

 if(isset($_POST['submit'])){ //is the form submitted?
     if(empty($_POST['user']) || empty($_POST['pass'])){
     header("Location: login.php");
     exit;
  } //check for empty user name or password
  $is_logged = false; //this is part of the process to see if they have a correct password or not, set to false right here to say no right pass... (will change later)
  foreach($logins as $login){
  $user = $_POST;
     if(($user["user"] == $login["user"]) && ($user["pass"] == $login["pass"])) {
   $is_logged = true;
   $_SESSION["logged_in"] = array($login["redirect"], true); //now, if they do have a correct password, set the session to true, and the variable.
  header("Location: ".$login["redirect"]);
  exit;
  }
 }
 if(!$is_logged){ echo '<script type="text/javascript">alert("Inncorect username or password");window.history.go(-1);</script>'; } //if none of the $logins arrays matched the input, give an error
 }
 ?>

您需要做的就是使用echo命令echo一些html,而不是使用Javascript

试试这个

echo '<p>Incorrect username or password</p>'
echo'用户名或密码不正确

'
这非常有效,但我可能会如何在表单下显示它?这会显示在页面的顶部。我建议你在网上浏览一些教程,或者买一本关于如何使用HTML和PHP的书。实验!试着自己找出如何把它放在页面的顶部,而不是试图让其他人为你做所有的工作!当然,当你需要帮助的时候,可以寻求帮助——但是关于如何做这样的事情,已经有很多信息了。你只需要看看:)。