<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); // LOGIN MODEL class Login_model extends CI_Model{ function __construct(){ parent::__construct(); } // VALIDATE METHOD public function validate(){ // grab user input $username = $this->security->xss_clean($this->input->post('username')); $password = $this->security->xss_clean($this->input->post('password')); $this->db->where('username', $username); $this->db->where('password', sha1($password)); $this -> db -> where('activated', 'yes');// Run the query<br> $query = $this->db->get('user_account');// Let's check if there are any results if($query->num_rows == 1)// If there is a user, then create session data { $row = $query->row(); $data = array( 'id' => $row->serial, 'name' => $row->name, 'email' => $row->email, 'password' => $row->password, 'type' => $row->type, 'address' => $row -> address, 'phone' => $row -> phone, 'pic' => $row -> pic,<br> 'validated' => true ); $this->session->set_userdata($data); return true; }// If the previous process did not validate return false;// then return false. } }
&GT;
答案 0 :(得分:2)
您是否确定在调用set_userdata时会抛出500错误?
您可以做的第一件事是启用error_reporting。一种方法是将您的环境设置为主index.php文件中的“development”,前提是您已在php.ini中启用了错误报告。执行此操作后,您可能会看到更详细的错误消息,可帮助您确定问题。
另一方面,查看代码时,我看到行'pic' => $row -> pic,<br>
,<br>
在初始化数组时肯定会产生错误,可能就是这种情况
答案 1 :(得分:0)
您应该将params传递给您的模型,并且不要在其中调用“$ this-&gt; input-&gt; post('username')”
参数:
public function validate($user, $pass){
还要验证是否已加载安全性和db lib。