我的网站有问题,问题出在这个: 当我尝试登录并输入正确的登录信息时,我不断收到的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