我的網站有問題,問題出在這個: 當我嘗試登錄並輸入正確的登錄信息時,我不斷收到的process_login頁和頭不想要我重定向回索引頁面......這只是發生在我的網頁,在本地主機上一切都很完美的罰款.. 代碼:一次又一次地在進程頁面上填充(空白頁面)
登錄模式
<div class="modal fade" id="login" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<center><div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<div class="alert alert-info">Login page</div>
</div></center>
<div class="modal-body">
<form role="form" action="process_login.php" method="post">
<div class="form-group">
<label for="exampleInputUsername">Username</label>
<input type="text" name="username" class="form-control" id="username_login" placeholder="Enter username"><span id="span_username_login"></span>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Password</label>
<input type="password" name="password" class="form-control" id="password_login" placeholder="Password"><span id="span_password_login"></span><br/>
</div>
<a href="#recover" data-toggle="modal" ><p>I've forgotten my password</a></p>
<div class="modal-footer">
<center><input type="submit" name="submit" class="btn btn-danger" value="Sign in"/></center>
</div>
</form>
</div>
</div>
</div>
</div>
的process_login .php頁面
<?php
require_once 'includes/initialize.php';
require_once 'classes/database.php';
require_once 'classes/bcrypt.php';
require_once 'classes/user.php';
if(isset($_POST['submit']))
{
$username = filter_input(INPUT_POST, 'username' , FILTER_SANITIZE_STRING);
$password = filter_input(INPUT_POST, 'password' , FILTER_SANITIZE_STRING);
//if input fields ain't filled , redirecting back to index page
if(empty($username) || empty($password))
{
$_SESSION['emptyfields'] = '';
header("Location: index.php");
}
//if that particular username doesnt exist in database , redirecting back to index page
if($userclass->userExists($username) == false)
{
$_SESSION['usernamedoesntexist'] = '';
header("Location: index.php");
}
//if that particular email isnt confirmed yet , redirecting back to index page
if($userclass->emailConfirmed($username) == false)
{
$_SESSION['emailnotconfirmed'] = '';
header("Location: index.php");
}
if($userclass->banned($username) == false)
{
//if that particular username is banned , redirecting back to index page
$_SESSION['banned'] = '';
header("Location: index.php");
}
$login = $userclass->login($username, $password);
if($login == false)
{
$_SESSION['errorwithlogin'] = ''; //incorect username - password combo
header("Location: index.php");
}
else
{
$_SESSION['user_auth'] = TRUE; //corect username - password combo
$_SESSION['user_id'] = $login;
$_SESSION['loginsuccessfull'] = '';
header("Location: index.php");
}
}
else
{
$_SESSION['errorwithprocessing'] = '';
header("Location: index.php");
}
?>
<?php
unset($_SESSION['errorwithprocessing']);
unset($_SESSION['loginsuccessfull']);
unset($_SESSION['errorwithlogin']);
unset($_SESSION['banned']);
unset($_SESSION['emailnotconfirmed']);
unset($_SESSION['usernamedoesntexist']);
unset($_SESSION['emptyfields']);
?>
類user.php的頁面(即在與記錄連接行)
public function login($username, $password)
{
global $db;
global $bcrypt;
$stm = $db->connection->prepare("SELECT `user_id`,`password` FROM `users` WHERE `username` = ?");
$stm->bindValue(1, $username);
try
{
$stm->execute();
$data = $stm->fetch();
$stored_password = $data['password'];
$id = (int) $data['user_id'];
if($bcrypt->verify($password, $stored_password) === true)
{
return $id;
}
else
{
return false;
}
}
catch(PDOException $e)
{
die($e->getMessage());
}
}
歡迎任何幫助,在此先感謝..
如果沒有進一步的代碼應該執行,不要忘了在'header'之後加'exit;'。並啓用錯誤消息的輸出。 – Cheery 2014-09-30 19:16:53
那麼,你應該首先在重定向後添加'exit;'(例如'header('Location:test.php'); exit;')。 PHP將繼續閱讀代碼,因此您必須在重定向時停止它。 – 2014-09-30 19:17:22
process_login.php腳本中有大量額外的代碼。無論發生什麼事情,你都希望將用戶發送回index.php,所以你最好只在最後的else語句後添加一次 – ksealey 2014-09-30 19:27:34