【发布时间】:2014-01-16 04:52:20
【问题描述】:
- CodeIgniter 问题:服务器 500 错误。
每当我调用 set_userdata() 函数时,它都会触发 Server 500 错误。登录示例代码如下。我在 SiteGround 上托管它。如果我删除 set_userdata 函数,代码可以正常工作,但登录不起作用。
<?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. } }?>
【问题讨论】:
-
你在加载会话库吗
-
在 application/config/autoload.php 中;如果尚未这样做,则自动加载“会话”库。
-
@Adarsh 是的,我已经加载了会话库..
标签: codeigniter session codeigniter-2 user-data