我使用php登录用户,这里是处理进程的代码,问题是一旦我提供用户名(uname)和密码,我必须单击“登录”按钮两次才能登录,第一次点击它页面只是重新加载第二次我点击它脚本发送给我面板继承人代码如果我可以得到一些帮助它会很好:
enter code here
<?php
require_once 'core/init.php';
if(input::exists()) {
if(token::check(input::get('token'))) {
$user = new user();
$remember = (input::get('remember') === 'on') ? true : false;
$login = $user->login(input::get('uname'), input::get('password'), $remember);
if($login) {
redirect::to('panel.php');
} else {
echo '<p>Sorry, that username and password wasn\'t recognised.</p>';
}
}
}
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Storon Management System</title>
<link rel="stylesheet" type="text/css" href="css/main.css">
<!--<link rel="stylesheet" type="text/css" href="FlatUI/css/flatui.css">-->
<link rel='stylesheet' type='text/css' href='http://fonts.googleapis.com/css family=Oxygen'>
<script type="text/javascript" src="js/fade.js"></script>
</head>
<body>
<div class="offerboxlog">
<?php include "includes/logo.php"; ?>
<h2>Under Construction..</h2>
<ul>
<li>Business Performance Insights</li>
<li>Book Management </li>
<li>Customer Management</li>
</ul>
<a href="register.php">Register For An Account</a>
</div>
<div id="loginf">
<div id="lform">
<h3>Login</h3><br>
<form action="" method="post">
<div class="field212">
<label for="uname">Username</label><br/>
<input type="text" name="uname" id="uname" class="login-form"><br>
</div><br/>
<div class="field212">
<label for="password">Password</label><br/>
<input type="password" name="password" id="password" class="login-form">
</div><br/>
<div class="field212">
<label for="remember">
<input type="checkbox" name="remember" id="remember"> Remember me
</label>
</div><br/>
<input type="submit" value="Log in" name="login" />
<input type="hidden" name="token" value="<?php echo Token::generate(); ?>" />
</form>
</div>
</div>
</body>
</html>
public function login($username = null, $password = null, $remember = false) {
if(!$username && !$password && $this->exists()) {
session::put($this->_sessionName, $this->data()->id);
} else {
$user = $this->find($username);
if($user) {
if($this->data()->password === hash::make($password, $this->data()->salt)) {
session::put($this->_sessionName, $this->data()->id);
if($remember) {
$hash = hash::unique();
$hashCheck = $this->_db->get('users_session', array('user_id', '=', $this- >data()->id));
if(!$hashCheck->count()) {
$this->_db->insert('users_session', array(
'user_id' => $this->data()->id,
'hash' => $hash
));
} else {
$hash = $hashCheck->first()->hash;
}
Cookie::put($this->_cookieName, $hash, Config::get('remember/cookie_expiry'));
}
return true;
}
}
}
return false;
}