我有一個單獨的php文件來處理我的網站上的登錄/註銷。登錄工作正常,但是當我嘗試登出時,我被告知在服務器上找不到該文件。處理程序文件在登錄時工作,註銷時找不到文件
此鏈接調用頁面的註銷:
<a href="/logansarchive/admin/do.login?action=out">Sign Out</a>
以下是文件中的代碼:
<?php
session_start();
if (isset($action) && $action == "out") {
// Log out
if (ini_get("session.use_cookies")) {
$params = session_get_cookie_params();
setcookie(session_name(), '', time() - 42000,
$params["path"], $params["domain"],
$params["secure"], $params["httponly"]
);
}
session_destroy();
header("Location: /logansarchive/admin/login.php?logged_out=1");
}
else {
$username = $_REQUEST["txt_username"];
$password = $_REQUEST["txt_password"];
$action = $_GET["action"];
$host = "127.0.0.1";
$user = "root";
$pass = "12157114";
try {
$dbh = new PDO("mysql:host=$host;dbname=logansarchive", $user, $pass);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e) {
echo $e->getMessage();
}
// Log in
$hashed_pass = hash("sha512", $password);
$sql = "select count(*) as count, adminid, adminname, DATE_FORMAT(lastlogin, '%W, %M %e, %Y @ %h:%i %p') AS lastlogin from admin where adminname = :name and adminpass = :pass";
$result = $dbh->prepare($sql);
$result->bindParam(":name", $username);
$result->bindParam(":pass", $hashed_pass);
$stmt = $result->execute();
$row = $result->fetch();
if ($row["count"] == 1) {
session_start();
$_SESSION["adminid"] = $row["adminid"];
$_SESSION["adminname"] = $row["adminname"];
$_SESSION["lastlogin"] = $row["lastlogin"];
$dbh = null;
header("Location: /logansarchive/admin/index.php");
}
else {
$dbh = null;
header("Location: /logansarchive/admin/login.php?login_attempt=1");
}
};
?>
這種行爲的任何解釋和(理想)的方式來解決它,將不勝感激。
derp,thanks:D – Ortund