【问题标题】:I'm just learning code.I want to know javascript or php code to show hidden paragraph <p>我只是在学习代码。我想知道 javascript 或 php 代码来显示隐藏的段落 <p>
【发布时间】:2016-10-10 17:04:23
【问题描述】:

&lt;p hidden&gt; Wrong email or password

html

$email=$_POST["login"];
$password=$_POST["password"];

$zz= "Select * from employer  where EMMail='$email' and EMpassword='$password'";
$sql="select * from student where StudentEmail='$email' and StudentPassword='$password'";

if $email && $password !=$zz || $email && $password !=$sql{

}

当用户名或密码不正确时如何显示该参数?

【问题讨论】:

    标签: javascript html text show hidden


    【解决方案1】:

    使用 PHP

    你可以简单地做这样的事情

    $failed=true;
    if $email && $password !=$zz || $email && $password !=$sql{
      $failed=false;
    }
    

    以及稍后找到此特定段落的位置:

    echo "<p ". ($failed?"hidden":"")+">Wrong password!</p>
    

    不同的页面

    我建议使用这样的不同页面:

    login
    |--index.php        //loginform
    |--login.php
    |--fail
    |  |--index.php     //with link to login form
    home
    |--index.php
    includes
    |--sql.php
    

    登录/index.php

    <html>
      <head>
        <title>
          Login
        </title>
      <body>
        <form action="login.php" method="POST">
          <table>
            <tr><td>User</td><td><input name="user" placeholder="johndoe123/></td></tr>
            <tr><td>Pass</td><td><input type="password" name="pass" placeholder="iluvyou%&-"/></td></tr>
            <tr colspan=2><td><input type="submit" value="Login" /></td></tr>
          </table>
        </form>
      </body>
    </html>
    

    login/login.php
    注意:使用准备好的语句!!!您使用的方法极易受到 SQL 注入和 XSS 的攻击。另外:请对密码进行哈希处理!

    <?php
      include "/includes/sql.php";
      $user=$_POST["user"];
      $passtry=$_POST["pass"];
      $sql="SELECT * FROM users WHERE user='?'";
      $cmd = $con->prepare($sql);
      $cmd->execute(array($user));
      if($entry=$cmd->fetchObject()){
        $pass=$entry->pass;
      }else{
        header("Location: fail");
        exit(0);
      }
      if(password_verify($passtry,$pass)){
        session_start();
        $_SESSION["login"]=true;
        $_SESSION["user"]=$user;
        header("Location: ../home");
      }else{
        header("Location: fail");
        exit(0);
      }
    ?>
    

    失败/index.html

    <html>
      <head>
        <title>
          Wrong password!
        </title>
      </head>
      <body>
        <p>Wrong password. <a href="..">Try again!</a></p>
      </body>
    </html>
    

    主页/index.html

    <?php
      session_start();
      if(!$_SESSION["login"]){
        header("Location: ../login/fail");
        exit();
      }
    ?>
    <html>
      <head>
        <title>
          <?php echo $_SESSION["user"] ?> - Home
        </title>
      </head>
      <body>
         PRIVATE CONTENT!!!
      </body>
    </html>
    

    includes/sql.php 取决于你的 sql 引擎。

    注意:在您的注册表单中,您必须使用password_hash()保存密码

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-01
      • 2021-08-24
      • 1970-01-01
      • 2017-07-25
      • 1970-01-01
      相关资源
      最近更新 更多