用于登录/注册的表单

问题描述 投票:-1回答:1

长期收听者,首次呼叫者。我花了几天的时间研究pHp中的登录/注册系统以用于我的网站。我的问题(也许有人问过),但是我的搜索记录中的每个链接都是紫色的,而我从未见过该问题的答案是:为什么似乎没有人使用相同的表单进行登录和注册?

这是我的表单的代码。它只是一个内联的单行,它隐藏在页面顶部,并在有人单击登录/注册按钮时显示出来:

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {font-family: Arial, Helvetica, sans-serif;}
* {box-sizing: border-box;}

.form-inline {  
  display: flex;
  flex-flow: row wrap;
  align-items: center;
  display: inline-block;
}

.form-inline label {
  margin: 5px 10px 5px 0;
}

.form-inline input {
  vertical-align: middle;
  margin: 5px 10px 5px 0;
  padding: 10px;
  background-color: #fff;
  border: 1px solid #ddd;
}

.form-inline button {
  padding: 10px 20px;
  background-color: royalblue;
  border: 1px solid #ddd;
  color: white;
  cursor: pointer;
  border-radius: 12px;
}

.form-inline button:hover {
  background-color: blue;
}

@media (max-width: 800px) {
  .form-inline input {
    margin: 10px 0;
  }

  .form-inline {
    flex-direction: column;
    align-items: stretch;
    display: inline-block;
  }
}

.loginDiv {
    text-align: center;
}
</style>
</head>
<body>
<div class = "loginDiv">
<form class="form-inline" action="/action_page.php">
  <input type="usernamel" id="username" placeholder="Username" name="email">
  <input type="email" id="email" placeholder="Enter email" name="email">
  <input type="password" id="pwd" placeholder="Enter password" name="pswd">
  <label>
    <input type="checkbox" name="remember"> Remember me
  </label>
  <button type="submit">Submit</button>
</form>
</div>
</body>
</html>

但是在此过程中,当您执行此步骤时:

<?php
   include("config.php");
   session_start();

   if($_SERVER["REQUEST_METHOD"] == "POST") {
      // username and password sent from form 

      $myusername = mysqli_real_escape_string($db,$_POST['username']);
      $mypassword = mysqli_real_escape_string($db,$_POST['password']); 

      $sql = "SELECT id FROM admin WHERE username = '$myusername' and passcode = '$mypassword'";
      $result = mysqli_query($db,$sql);
      $row = mysqli_fetch_array($result,MYSQLI_ASSOC);
      $active = $row['active'];

      $count = mysqli_num_rows($result);

      // If result matched $myusername and $mypassword, table row must be 1 row

      if($count == 1) {
         session_register("myusername");
         $_SESSION['login_user'] = $myusername;

         header("location: welcome.php");
      }else {
         $error = "Your Login Name or Password is invalid";
      }
   }
?>

并转到“其他”部分,为什么不能仅为输入的值创建一个帐户?

是因为他们害怕使数据库中的电子邮件地址和用户名拼写错误而混乱?因为那不是一直都在发生吗?

或者是否存在我所缺少的更具技术性的,也许是超简单的解释?我不会把它过去。

非常感谢!

编辑:阅读了答复之后,我开始认为所涉及的输入验证将比仅实现当前范例更为乏味。

例如,如果我以“ crashddy”身份登录,但正确设置了电子邮件地址和个人资料,则必须在验证时将其捕获,然后作为错误返回。

php authentication registration
1个回答
-1
投票

最好为登录和注册**具有单独的功能。这将增强系统的安全性,并减少**电子邮件/用户名的复制

© www.soinside.com 2019 - 2024. All rights reserved.