2014-01-16 60 views
1

CodeIgniter set_userdata()觸發服務器500錯誤

  1. 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. 
        } 
    } 
    

    ?>

+1

你在application/config/autoload.php中加載會話庫 –

+0

;自動加載「會話」庫,如果還沒有這樣做。 – Arunu

+0

@Adarsh是啊我已經加載會話庫.. – user3200990

回答

2

你確定調用set_userdata當500錯誤被拋出?

你可以做的第一件事是啓用error_reporting。做到這一點的一種方法是在你的主要index.php文件中設置你的環境爲'development',同時提供你已經在你的php.ini中啓用了錯誤報告。完成此操作後,您可能會看到更詳細的錯誤消息,可幫助您識別問題。

在另一方面看你的代碼,我看到你的初始化數組時'pic' => $row -> pic,<br><br>肯定會產生錯誤的路線,也許是這種情況

+0

謝謝!你是一個救星!刪除'pic'=> $ row - > pic。解決了問題!實際上問題是BLOB被保存在數據庫中而不是圖像路徑中。 **摘要:**在會話中保存大量數據導致了問題。 根據(http://ellislab.com/codeigniter%20/user-guide/libraries/sessions.html) **注意:** Cookie只能容納4KB的數據,所以要小心不要超過容量。特別是加密過程會產生比原始數據字符串更長的數據字符串,因此請仔細跟蹤您要存儲的數據量。 – user3200990

0

你應該通過PARAMS到模型不叫在它

PARAMS 「這 - $>輸入 - >後( '用戶名')」:

public function validate($user, $pass){

此外,還應確保您已加載的安全性和DB庫。