我創建了一個管理面板,我可以編輯我的網站,但我總是需要登錄兩次才能訪問我的管理面板。我如何能夠避免這種情況?如何避免在我的管理面板(PHP)登錄兩次
我在一個現有的管理面板只用一次登錄,我複製了我的門戶網站的所有內容,但結果是我仍然需要登錄兩次。
這是我的連接。
<?php
$errormsg = "";
if (isset($_POST['submit']))
{
$email = $_POST['email'];
$pass = $_POST['password'];
$salt = sha1(md5($pass));
$passwordencrypted = md5($pass . $salt);
$stmt=$db->prepare("SELECT count(*) as count FROM users WHERE email=?");
$stmt->execute(array($email));
while($row=$stmt->fetch(PDO::FETCH_ASSOC)) {
$row_count = $row['count'];
}
if ($row_count == 1)
{
$statement = $db->prepare("SELECT * FROM users where email = :name");
$statement->execute(array(
':name' => "$email"
));
while ($row = $statement->fetch(PDO::FETCH_ASSOC)) {
$userID = $row['userID'];
$lpass = $row['password'];
$userlevelID = $row['userlevelID'];
}
if ($lpass == $passwordencrypted) {
$_SESSION["userID"] = $userID;
$_SESSION["userlevelID"] = $userlevelID;
if (getenv('HTTP_X_FORWARDED_FOR')) {
$pipaddress = getenv('HTTP_X_FORWARDED_FOR');
$ipaddress = getenv('REMOTE_ADDR');
$ipaddd = "Logged In using Proxy IP address is: " . $pipaddress . "(via $ipaddress)";
} else {
$ipaddress = getenv('REMOTE_ADDR');
$ipaddd = "Logged In using IP address: $ipaddress";
}
$currentdatetime = date('Y-m-d H:i:s');
$auditaction = "Logged In";
$auditdetail = $ipaddd;
$stmt = $db->prepare("INSERT INTO audittrail(userID,[action],detail,[when]) VALUES(:uid,:action,:detail,:when)");
$stmt->execute(array(
':uid' => $userID,
':action' => $auditaction,
':detail' => $auditdetail,
':when' => $currentdatetime
));
$_SESSION['isLoggedIn'] = true;
/////////////////////////////////////////
//$_SESSION['timeOut'] = 5;
$_SESSION['timeOut'] = 600;
$logged = time();
$_SESSION['loggedAt']= $logged;
if ($userlevelID == 1) {
} elseif ($userlevelID == 2) {
header("location:portal/");
}
} else {
header("location:index.php?error=c4ca4238a0b923820dcc509a6f75849b"); // 1
}
}
else {
header("location:index.php?error=c81e728d9d4c2f636f067f89cc14862c"); //2
}
}
?>
檢查管理面板登錄頁面上的用戶時的會話值。如果會話值存在,則將其重定向到管理面板的主頁面。 – PHPExpert