我有一个 PHP 项目,目前位于本地主机中。
我面临的问题是,当我打开网址并尝试登录时,它不允许我登录,并且会恢复到同一页面。但是如果我尝试先登录其他PHP项目,然后登录我的PHP项目它将能够登录。
那么出现这个问题的原因是什么呢?有人可以帮助我吗?
代码
<?php
include "../setting/config.php";
session_start();
if(!isset($_POST['login']))
{
$_SESSION['test'];
}
if(isset($_POST['login'])){
$username = $_POST['username'];
$password = $_POST['password'];
//ADMIN
$query1 = "SELECT * FROM umd_login WHERE username='$username' AND password='$password'";
$query_run=mysqli_query($conn, $query1);
$level = mysqli_fetch_array($query_run);
if(count(fetchAll($query1)) > 0){ //this is to catch unknown error.
foreach(fetchAll($query1) as $row){
if ($row['username'] == $username && $row['password'] == $password) {
$_SESSION['test'] = true;
$_SESSION['username']= $_POST['username'];
if($level['user_level_id'] == "1"){
header('location:UMD_home.php');
exit;
}
} else {
alert();
}
}
}
function alert(){
echo "<script>alert('Invalid username or password. Please try again.')</script>";
}
}
if (isset($_POST['login'])) {
$username = $_POST['username'];
$password = $_POST['password'];
//UMD,CMD
$query2 = "SELECT * FROM registered_accounts WHERE username='$username' AND password='$password'";
$query_run=mysqli_query($conn, $query2);
慕仙森
长风秋雁
梦里花落0921