$\u POST/$\u未在PHP/Codeigniter/Apache中设置请求变量
首先,在本地安装的XAMPP上,这可以很好地工作。但是,在外部(WAMP)服务器上,它不是$\u POST/$\u未在PHP/Codeigniter/Apache中设置请求变量,php,apache,codeigniter,post,Php,Apache,Codeigniter,Post,首先,在本地安装的XAMPP上,这可以很好地工作。但是,在外部(WAMP)服务器上,它不是 class Authentication extends MY_Controller { function Authentication () { parent::__construct (FALSE); $this->template->set_template('authentication'); } /** *
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>
它只给出一个空白的“Array()”。有什么想法吗?因为我刚离开他们:)
其他内容
顺便说一句,在不相关的页面上,服务器返回了正确的内容,但由于某种原因返回了404头。我已经预兆它会起作用,但我不知道——也许这是一个显而易见的问题,我没有考虑到 如果您使用
表单
助手,是否仍会发生这种情况
要使用它:
在控制器中添加:
$this->load->helper('form')代码>
在模板中,而不是:
我一直是个傻瓜。添加以下内容非常重要:
LoadModule rewrite_module modules/mod_rewrite.so
如果您打算使用Apache中的httpd.conf,请访问它!;)
今天的教训-不要因为你在自己的电脑上设置了东西就认为它是在另一台电脑上设置的…这会有什么变化?海亚·波琳娜-谢谢你回应我的呼救声:)我已经尝试过了,但不幸的是,它没有起到很大的作用。我的怀疑是服务器出现了一些问题,但这是一个我不太了解的领域!我可能完全错了…@Shomz-codeigniter在表单中使用了crsf保护,因此有一点可能是因为crsf令牌不存在而导致某些东西不起作用。使用form\u open
codeigniter时,会自动向带有crsf令牌的表单中添加一个input hidden
@AlgyTaylor-因为所有东西都在本地服务器上工作,所以正如您所说,外部服务器似乎有问题。我假设您已经正确设置了config.php
文件中的所有路径?@paulina-根本不知道form_open,谢谢-已经学到了一些新东西,而且还不到上午9点!)是的,在我看来,配置文件中的所有路径都是正确的。。。
LoadModule rewrite_module modules/mod_rewrite.so