我的登录过程有问题。我正在使用会话并重新加载,以便我可以拥有一个单页网站。在 Chrome 上,这会增加一个 ? 所以 url 的结尾(任何时候 ? 存在,登录不起作用)。在 Firefox 和 Chrome 上,登录-注销过程只运行一次,然后登录停止工作。我的 index.php 页面上有一个 if 语句,它基本上是:
if($_SESSION["LoggedIn"] != true) {
/*display login button*/
}
else {
/*display logout button*/
}
然后我设置我的脚本文件:
$("#toolbarTitle-Login").click(function() {
var loginEmail = $("#toolbarTextbox-Email").val();
var loginPassword = $("#toolbarTextbox-Password").val();
if (loginEmail != "") {
$("#toolbarPleaseWait").text("Please wait...");
$.post(
'ajax/loginProcess.php',
{
'email': loginEmail,
'password': loginPassword
},
function (response) {
window.location.reload(true);
}
);
}
});
$("#toolbarTitleLoggedIn-Logout").click(function() {
$("#toolbarPleaseWait").text("Logging out...");
$.post(
'ajax/logoutProcess.php',
{
},
function (response) {
window.location.reload(true);
}
);
});
然后我的处理页面loginProcess.php:
<?php
session_start();
include "../incl/databaseConnection.php";
$email = $connection->real_escape_string($_POST["email"]);
$password = $connection->real_escape_string(md5($_POST["password"]));
$sql = "SELECT clientId
FROM clients
WHERE (studentEmail = '$email' AND studentPassword = '$password') OR (parentEmail = '$email' AND parentPassword = '$password');";
if (!$result = $connection->query($sql)) {
die ('There was an error running the query [' . $connection->error . ']');
}
$rows = $result->num_rows;
$row = $result->fetch_assoc();
if ($rows == 1) {
$_SESSION["loggedIn"] = true;
$_SESSION["clientId"] = $row["clientId"];
}
else if ($rows > 1) {
echo 'CHOOSE BETWEEN ACCOUNTS';
}
else if ($rows == 0) {
echo 'SHOW ERROR MESSAGE';
}
$connection->close();
?>
下一个 logoutProcess.php:
<?php
session_start();
session_unset();
?>