require_once('includes/user_config.php');
//check if already logged in move to home page
if( $user->is_logged_in() ){ header('Location: index.php'); }
//process login form if submitted
if(isset($_POST['submit'])){
$username = $_POST['username'];
$password = $_POST['password'];
$status = $_POST['status'];
if($user->login($username,$password)){
$status = 0;
header('Location: house/admincp.php');
exit;
}
$username = $_POST['username'];
$password = $_POST['password'];
if($user->login($username,$password)){
$_SESSION['username'] = $username;
$status = '1';
header('Location: house/memberpage.php');
exit;
}else {
$error[] = 'Wrong username or password or your account has not been activated.';
}
<div class="row">
返回主页
<?php
//check for any errors
if(isset($error)){
foreach($error as $error){
echo '<p class="bg-danger">'.$error.'</p>';
}
}
if(isset($_GET['action'])){
//check the action
switch ($_GET['action']) {
case 'active':
echo "<h2 class='bg-success'>Your account is now active you may now log in.</h2>";
break;
case 'reset':
echo "<h2 class='bg-success'>Please check your inbox for a reset link.</h2>";
break;
case 'resetAccount':
echo "<h2 class='bg-success'>Password changed, you may now login.</h2>";
break;
}
}
?>
<!- Username starts here ->
<div class="form-group">
<input type="text" name="username" id="username" class="form-control input-lg" placeholder="User Name" value="<?php if(isset($error)){ echo $_POST['username']; } ?>" tabindex="1">
</div>
<div class="form-group">
<div class="row">
<div class="col-xs-9 col-sm-9 col-md-9">
<a href='reset.php'>Forgot your Password?</a>
</div>
</div>
<hr>
<div class="row">
<div class="col-xs-6 col-md-6"><input type="submit" name="submit" value="Login" class="btn btn-primary btn-block btn-lg" tabindex="5"></div>
</div>
</form>
</div>
</div>
答案 0 :(得分:0)
if()
应该有$status
声明。
$username = $_POST['username'];
$password = $_POST['password'];
$status = $_POST['status'];
if($user->login($username,$password)){
if ($status == 0) {
header('Location: house/admincp.php');
} else {
header('Location: house/memberpage.php');
}
exit();
} else {
$error[] = 'Wrong username or password or your account has not been activated.';
}
但对我来说,让用户指定他们是否是登录表单中的管理员或用户似乎很奇怪。您可能应该从$user->login();
返回状态,这可以从数据库中获取。