문제

  1. CodeIgniter Issue: Server 500 Error. Whenever I call set_userdata() function, it triggers Server 500 Error. Sample code of login is below. I'm hosting it on SiteGround. if I remove set_userdata function, the code works fine except login won't work.

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

    ?>

도움이 되었습니까?

해결책

Are you sure that the 500 error is thrown when calling set_userdata?

First thing you can do is enable error_reporting. One way to do this is by setting your environment to 'development' in your main index.php file, provided also that you have enabled error reporting in your php.ini. After doing this you will probably see a more detailed error message that will help you identify the problem.

On the other hand looking at your code I see the line 'pic' => $row -> pic,<br> and that <br> definitely produces an error when initializing your array, maybe this is the case

다른 팁

You should pass params to your model and don't call "$this->input->post('username')" in it

Params :

public function validate($user, $pass){

Also verify you have loaded security and db lib.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top