Php 登录页面错误
我在登录页面中遇到问题。当我按下“登录”按钮时,只有选中“记住我”复选框,它才会将我带到用户面板。如果未选中,则它将保留在登录页面上。我想不出这个错误Php 登录页面错误,php,forms,login,Php,Forms,Login,我在登录页面中遇到问题。当我按下“登录”按钮时,只有选中“记住我”复选框,它才会将我带到用户面板。如果未选中,则它将保留在登录页面上。我想不出这个错误 include("Database/database.php"); session_start(); if(isset($_COOKIE['username']) and isset($_COOKIE['passcode'])) { $username = $_COOKIE['username']; $passcode = $_C
include("Database/database.php");
session_start();
if(isset($_COOKIE['username']) and isset($_COOKIE['passcode'])) {
$username = $_COOKIE['username'];
$passcode = $_COOKIE['passcode'];
$_SESSION['name'] = $username;
$_SESSION['pwd'] = $passcode;
header("Location: useraccount.php"); /*Checks if cookies are set then takes me directly to useraccount.php */
} else if (isset($_POST['login'])) {
$username = $_POST['username'];
$userpwd = $_POST['userpwd'];
$rem = $_POST['remember'];
$query = "SELECT * FROM login WHERE userName = '$username' AND Password = '$userpwd'";
$result = mysqli_query($link, $query);
$row = mysqli_num_rows($result);
if ($row > 0) {
$_SESSION['name'] = $username;
$_SESSION['pwd'] = $userpwd;
if (isset($_POST['remember'])) /*if remember me checkbox is checked than it set cookies and it takes me to useraccount.php page. But if I donot check the check box (remember me) than I am where I am on login page. */
{
setcookie("username", $username, time()+60*60*7);
setcookie("passcode", $userpwd, time()+60*60*7);
}
header("Location: useraccount.php"); /* It should procees to useracocunt.php page but it stays on login.php*/
} else {
header("Location: login.php"); /*Used this for testing purpose if login fails it takes me to homepage which is working fine*/
}
mysqli_close($link);
}
}
如果将“添加到脸颊”语句保存到会话中,则将其添加。因为您添加了会话,但没有任何地方检查它
<?php
include("Database/database.php");
session_start();
if(isset($_COOKIE['username']) and isset($_COOKIE['passcode']))
{
$username = $_COOKIE['username'];
$passcode = $_COOKIE['passcode'];
$_SESSION['name'] = $username;
$_SESSION['pwd'] = $passcode;
header("Location: useraccount.php"); /*Checks if cookies are set then takes me directly to useraccount.php */
}
else if(isset($_POST['login']))
{
$username = $_POST['username'];
$userpwd = $_POST['userpwd'];
$rem = $_POST['remember'];
$query = "SELECT * FROM login WHERE userName = '$username' AND Password = '$userpwd'";
$result = mysqli_query($link, $query);
$row = mysqli_num_rows($result);
if($row > 0)
{
$_SESSION['name'] = $username;
$_SESSION['pwd'] = $userpwd;
if (isset($_POST['remember'])) /*if remember me checkbox is checked than it set cookies and it takes me to useraccount.php page. But if I donot check the check box (remember me) than I am where I am on login page. */
{
setcookie("username", $username, time()+60*60*7);
setcookie("passcode", $userpwd, time()+60*60*7);
}
header("Location: useraccount.php"); /* It should procees to useracocunt.php page but it stays on login.php*/
}
else
{
header("Location: login.php"); /*Used this for testing purpose if login fails it takes me to homepage which is working fine*/
}
mysqli_close($link);
} if (isset($_SESSION['name']) and isset($_SESSION['pwd'])){
header("Location: useraccount.php"); /* It should procees to useracocunt.php page but it stays on login.php*/
}
?>
我找到了这个问题的解决方案。这都是我的错误,因为如果我没有设置cookies,我会将标题重定向回登录页面
- 所以,若你们面临着和标题相关的问题,那个么检查你们是否将它标题到了那个文件的正确位置“url”,或者
- 一定是拼错了
- 它帮助我解决了同样的问题。登录后,我将其重定向到同一个登录页面。没有正确设置Cookie条件您好,我以前做过,但没有帮助,您可以看到,如果用户检查设置了Cookie,则“记住”是一个例外,但他仍应登录到他的帐户。我添加了检查会话设置的if语句,因此该语句丢失。请尝试添加此项。但请确保在useraccount.php中不仅检查cookie,还检查会话。问题是我将其从useraccount页面重定向到登录页面会话从来都不是问题