javascript - 登录将我带到相同的登录表单,并且在输入正确的用户名和密码时无法登录
问题描述
我做了一个登录浮动表单。每当我尝试使用正确的用户名和密码登录时,它都会将我带到登录表单,但这次是在一个简单的设计中并进入另一个页面。当我尝试从那里登录时,什么也没有发生。谁能帮我这个?
//登录测试.php
<div class="popUpLogin">
<div class="blackBox activate"></div>
<div class="wrapper activate">
<div class="title">
Login Form
<button onclick=" enableActivate() ">×</button>
</div>
<form action="includes/login.inc.php" method="post">
<div class="field">
<input type="text" name="name" required>
<label>Email Address</label>
</div>
<div class="field">
<input type="password" name="pwd" required>
<label>Password</label>
</div>
<div class="content">
<div class="checkbox">
<input type="checkbox" id="remember-me">
<label for="remember-me">Remember me</label>
</div>
<div class="pass-link">
<a href="#">Forgot password?</a>
</div>
</div>
<div class="field">
<input type="submit" value="Login">
</div>
<div class="signup-link">
Not a member? <a href="signup.php">Signup now</a>
</div>
</form>
</div>
<?php
if(isset($_GET["error"])){
if($_GET["error"] == "emptyinput"){
echo "<p>Fill in all feilds!</p>";
} else if($_GET["error"] == "wronglogin") {
echo "<p>Incorrent Login Information</p>";
}
}
?>
</div>
//login.inc.php
<?php
if(isset($_POST["submit"])){
$username = $_POST["uid"];
$pwd = $_POST["pwd"];
require_once 'dbh.inc.php';
require_once 'functions.inc.php';
if(emptyInputLogin($username, $pwd) !== false){
header("location: ../logintest.php?error=emptyinput");
exit();
}
loginuser($conn, $username, $pwd);
} else {
header("location: ../logintest.php");
exit();
}
//functions.inc.php
function loginuser($conn, $username, $pwd) {
$uidExists = uidExists($conn, $username, $username);
if($uidExists === false){
header("location: ../logintest.php?error=wronglogin");
exit();
}
$pwdHashed = $uidExists["usersPwd"];
$checkPwd = password_verify($pwd, $pwdHashed);
if ($checkPwd === false){
header("location: ../logintest.php?error=wronglogin");
exit();
} else if ($checkPwd === true){
session_start();
$_SESSION["userid"] = $uidExists["usersID"];
$_SESSION["useruid"] = $uidExists["usersUid"];
header("location: ../index.php");
exit();
}
}
在我的 header.php 中:
<div class="nav">
<?php
if(isset($_SESSION["useruid"])){
echo "<a href='index.php' class='login' style='color: rgba(47, 128, 237,
1);'>Profile</a>";
} else {
echo "<button onclick='disableActivate()' class='login' style='color: rgba(47,
128, 237, 1);'>Login</button>";
echo "<button onclick='document.location='signup.php' ' class='navSignup'> Get
your free card!</button>";
}
?>
</div>
<?php
include 'logintest.php';
?>
<script>
function disableActivate() {
document.querySelectorAll(".wrapper")[0].classList.remove("activate");
document.querySelectorAll(".blackBox")[0].classList.remove("activate");
}
function enableActivate() {
document.querySelectorAll(".wrapper")[0].classList.add("activate");
document.querySelectorAll(".blackBox")[0].classList.add("activate");
}
</script>
解决方案
通常,此事件发生在表单提交之后。
我在提供的代码中看到的可能是您忘记为按钮分配名称。你需要做的是:
HTML:
<input type="submit" name="login" value="Login">
登录.inc.php:
if (isset($_POST['login'])){
#login
}else{
#deny access
}
在编译这段代码时,浏览器运行代码并搜索一个名为 login 的按钮,然后采取行动
推荐阅读
- c++ - 允许 Cinder CMake 项目的麦克风访问
- c++ - 将紧凑型浮点值数组转换为浮点数数组的更简洁方法
- c# - 使用 CopyToAsync 时,FileStream 使用块未正确处理文件
- hibernate - 休眠 <-> H2。浮点映射异常
- azure-cosmosdb - Cosmos DB SDK V2 中的首选位置
- php - 聊天应用程序(而不是套接字)的 XHR 长轮询?
- ios - 警报阻止 Segue-iOS
- postgresql - 如何从 Azure 数据工厂连接到 AWS 托管的 Postgres 数据库?
- python - 使用 Python 抓取动态网页(输入日期)
- spring - Spring WebClient 中的连接池