首页 > 解决方案 > 尝试创建一个基本的php登录系统

问题描述

这里是初学者编码器。我正在尝试使用 html 和 php 构建一个非常基本的 php 登录系统。但我需要一些帮助:

<html>
<head></head>
<body>

   <form method="POST">
        User <input type="text" name="user"></input><br/>
        Pass <input type="password" name="pass"></input><br/>
        <input type="submit" name="submit" value="Go"></input>
        </form>  

和:

    <?php

$user = $_POST['user'];
$pass = $_POST['pass'];

$passw= md5($pass);


if ($user == "admin" && $passw == "8b1a9953c4611296a827abf8c47804d7") {
    echo "Login completed";
} else {
    echo "Try Again Please";
}
?>

</body>
       </html>

但是这里有些东西不太正常,当我输入用户名和密码,然后单击按钮时,屏幕就像什么都没发生一样刷新。

我错过了什么?!

标签: phphtml

解决方案


通常在登录页面上有一个输入页面,您可以在其中输入您的凭据,即将变量提交到另一个站点。那么你必须有这样的东西,在巫婆中你包括凭证形式。

<form method="post" action="https://example.com/landing_site.php">
<?php
    include "credencial_html.php";
?>
</form>

credencial_html.php 看起来像这样(简单的 html 代码):

 User <input type="text" name="user"><br/>
 Pass <input type="password" name="pass"><br/>
 <input type="submit" name="submit" value="Go">

现在你做了那个“如果”部分。...如果凭据正确,您可以发布,如果不正确,请再次输入输入框,然后说重试...

<?php

define('rightpass', '8b1a9953c4611296a827abf8c47804d7');
define('rightuser', '21232f297a57a5a743894a0e4a801fc3'); // md5('admin') ;-)    

$user = md5($_POST['user']);
$pass = md5($_POST['pass']);


if ($user == rightuser && $pass == rightpass) {
    echo "Login completed";
} else {
    echo "Try Again Please";
    include "credencial_html.php";
}

?>

推荐阅读