Php codeigniter正在设置密码!
我尝试在codeigniter表单中设置密码。。。 在我看来一切都很好,但无论我使用哪个密码,表单仍然提交 以下是控制器中的代码:Php codeigniter正在设置密码!,php,codeigniter,passwords,Php,Codeigniter,Passwords,我尝试在codeigniter表单中设置密码。。。 在我看来一切都很好,但无论我使用哪个密码,表单仍然提交 以下是控制器中的代码: class MyBlog extends Controller{ function MyBlog(){ parent::Controller(); $this->load->helper(array('url','form','html')); //here we load some classes that we
class MyBlog extends Controller{
function MyBlog(){
parent::Controller();
$this->load->helper(array('url','form','html')); //here we load some classes that we use
$this->load->scaffolding('entries'); //scaffolfing is a feature that lets you add or remove elements from the database
$this->load->scaffolding('comments');
$this->load->library('form_validation');//load validation class used to validate our forms...
}
function index(){
$data['title'] = "My Blog Title"; //the title of my blog
$data['query'] = $this->db->get('entries'); //here we make a small query to entries table
$this->load->view('myBlog_view', $data); ///load all data variables on myBlog_view.php
//this is also for the form validation
$this->form_validation->set_rules('title', 'Title', 'required');
$this->form_validation->set_rules('body', 'Body', 'required');
$this->form_validation->set_rules('author', 'Author', 'required');
$this->form_validation->set_rules('pass', 'Pass', 'callback_pass_check');
function pass_check($str) {
if ($str == 'baywatch'){
return TRUE;
}
else{
return FALSE;
}
}
if ($this->form_validation->run() == TRUE)
{
$this->myBlog_insert();
//$this->load->view('formSuccess_view');
}
}
function myBlog_insert(){
$insert = array( 'title' => $_POST['title'],
'body' => $_POST['body'],
'author' => $_POST['author']
);
$this->db->insert('entries',$insert);
redirect('myBlog/');
}
}
这是我的表格:
<div class="theForm">
<?php echo $this->form_validation->error_string; ?>
<?php echo validation_errors(); ?>
<?php echo form_open('myBlog'); ?>
<label for="title">Title:</label>
<input type='text' name="title" size="40" id="title" />
<p>
<label for="body">Body:</label>
<textarea name="body" rows = "10" cols="60" id="body"></textarea>
</p>
<p>
<label for="author">Author:</label>
<input type="text" name="author" size="40" id="author"/>
</p>
<p>
<label for="pass">Password:</label>
<input type="password" name="pass" size="38" id="pass"/>
</p>
<p><input type="submit" value="Submit New Post"/></p>
</form>
</div>
</body>
</html>
标题:
正文:
作者:
密码:
有什么想法吗?
提前感谢密码:
<label for="pass">Password:</label>
<input type="text" name="pass" size="38" id="author"/>
输入类型是text no password,id='pass'。好的,首先要做几件事: 1) id应该是唯一的。ie您的作者字段和密码字段不应具有相同的id。 2) 密码文件应使用“密码”而不是“文本”类型 我认为出现问题的原因是回调函数pass\u check()的问题。尝试将功能更改为:
function pass_check($pass)
{
if($pass !== 'baywatch')
{
return FALSE;
}
顺便说一句,脚手架现在已经被弃用了。我可以建议您考虑使用模型和活动记录类作为与数据库交互的一种方式吗?而且,这并不是一种非常安全的密码处理方式。查看一些CI身份验证库,看看是否可以实现其中的一个。好的,伙计们……我发现了问题所在……函数pass\u check是在index()中声明的……出于某种原因,它需要作为类的一个方法位于外部……希望这能帮助其他人。。。我对所有的建议都不满意 感谢所有的建议…我更改了pass\u check代码,但仍然没有完成工作…(我不认为这两个函数在某种程度上有任何真正的区别…)仍然会提交表单,无论我键入什么密码。这两个函数基本相同。我尝试将字段名作为参数传递,看看这是否有帮助,只是稍微简化了语法。