【发布时间】:2016-04-09 21:58:17
【问题描述】:
我的登录系统突然停止工作,我无法修复它,我一直在研究它,似乎数据没有回传,但我找不到问题。
这是我的看法:
<?php if(! is_null($err)) echo "<div class=\"alert alert-danger\">".$err."</div>";?>
<form class="form-signin" action="<?php echo site_url("user/validate"); ?>" method="post">
<h2 class="form-signin-heading">Please sign in</h2>
<label for="email" class="sr-only">Email address</label>
<input type="email" name="email" class="form-control" placeholder="Email address" required autofocus>
<br/>
<label for="password" class="sr-only">Password</label>
<input type="password" name="password" class="form-control" placeholder="Password" required>
<br/>
<button class="btn btn-lg btn-primary btn-block" name="submit" type="submit">Sign in</button>
</form>
</div>
这是我在用户控制器中的验证函数:
public function validate()
{
$email = $this->input->post('email');
$password = $this->input->post('password');
// Load the model
echo "$email and $password sent";
print_r($this->input->post());
exit();
$this->load->model('User_model');
// Validate user's login details
$result = $this->User_model->validate($email, $password);
// Now we verify the result
if($result == 0){
// If user did not validate, then show them login page again
$err = 'Invalid email and/or password.';
$this->login($err);
}else{
// If user did validate send him to homepage after setting the credentials
$this->session->set_userdata($result);
redirect(site_url("/index/index"));
}
}
echo 和 print_r 显示没有发布任何数据。
经过一番研究,我发现问题应该是.htaccess文件,这是我当前的.htaccess:
RewriteEngine On
RewriteRule ^(application) - [F,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
但它不起作用。
【问题讨论】:
-
不,$this->input->post() 只是空的
-
这意味着你的表单操作是错误的,因为值没有进入验证函数
-
查看表单动作的路径
-
如果你的url中有index.php,使用site_url(),如果你的url中没有index.php,使用base_url()。
标签: php .htaccess codeigniter codeigniter-3