首先,在本地安装的XAMPP上,这非常有效。但是,在外部(WAMP)服务器上,它没有。
class Authentication extends MY_Controller {
function Authentication () {
parent::__construct (FALSE);
$this->template->set_template('authentication');
}
/**
* Allows the user to log in to the system
*/
public function index () {
$person = $this->session->userdata("person");
if (AUTHENTICATION_DISABLED || !empty($person)) {
redirect('');
}
// if the user isn't already logged in, then they require a login page.
$this->session->set_userdata("login_attempt", $this->session->userdata("login_attempt") + 1);
$this->form_validation->set_rules("username", "User name", "required");
$this->form_validation->set_rules("password", "Password", "required");
if ($this->form_validation->run() !== FALSE) {
$this->load->model("person_model");
$person = $this->person_model->get_person($this->input->post("username"));
if ($person) {
$this->session->set_userdata("person", $person);
redirect('');
}
}
if ($this->session->userdata("login_attempt") > MAX_LOGIN_ATTEMPTS && !DISABLE_LOGIN_LIMIT) {
$this->log('User locked out', __FILE__, __LINE__, Array (
'login_attempts' => $this->session->userdata('login_attempt'),
'lockout_time' => FAILED_ACCESS_LOCKOUT_TIME
));
$this->session->sess_expiration = FAILED_ACCESS_LOCKOUT_TIME; // lock the user out for the amount of time specified in the config
$this->data['max_login_attempts'] = MAX_LOGIN_ATTEMPTS;
$this->data['lockout_time_mins'] = FAILED_ACCESS_LOCKOUT_TIME / 60;
$this->data['try_again_time'] = date('H:i', strtotime('+' . ($this->data['lockout_time_mins'] + 1) . ' minutes'));
$this->template->write('title', 'Connection refused');
$this->template->write_view('content', 'authentication/refused', $this->data);
$this->template->render();
} else {
$this->template->write('title', 'Log In');
$this->template->write_view('content', 'authentication/login');
$this->template->render();
}
}
/**
* Allows a user to log out of the system
*/
public function logout () {
if ($this->session->userdata('user_id') || DONT_REQUIRE_USER_ID) {
$this->session->sess_destroy();
$this->template->write('title', 'Logged Out');
$this->template->write_view('content', 'authentication/logout');
$this->template->render();
} else {
$this->log('Unauthorised access of logout page', __FILE__, __LINE__);
show_404();
}
}
}
表格很简单......
<form method="post" action="<?= site_url('authentication') ?>">
<label for="username">Username:</label>
<input type="text" name="username" value="" />
<label for="password">Password</label>
<input type="password" name="password" value="" />
<button type="submit">Log In</button>
</form>
POST变量也是根据Firebug发送的,但如果我应该输入类似
的内容die(print_r($_POST, TRUE))
它只是给出一个空白的“Array()”。有任何想法吗?我很新鲜他们:)
其他资料 顺便提一下,在非相关页面上,服务器一直在返回正确的内容,但出于某种原因使用404标头。我已经提出工作,但我不知道 - 也许这是一个我不知道的明显问题。 ;)
答案 0 :(得分:1)
如果您使用form
帮助程序,它仍然会发生吗?
使用它:
在控制器中添加:
$this->load->helper('form');
在您的模板中,而不是:
<form method="post" action="<?= site_url('authentication') ?>">
写
<?=form_open('authentication')?>
答案 1 :(得分:0)
我一直是个傻瓜。添加内容非常重要:
LoadModule rewrite_module modules/mod_rewrite.so
如果您打算使用它,请访问Apache中的httpd.conf! ;)
当天的课程 - 不要因为你已经在自己的计算机上进行设置而假设在另一台计算机上设置了某些内容......