Example
/*****************************
login user
@required : username and password via post method only
@return user data if login successfull otherwise error message
****************************/
public function login(){
$username=$this->input->post('username');
$password=$this->input->post('password');
if($username && $password){
//check username and password
if($this->login_credential['username']==$username && $this->login_credential['password']==$password){
//set user data to store in session
$userdata = array(
'username' => $this->login_credential['username'],
'email' => $this->login_credential['email'],
'logged_in' => true
);
//set session
$this->session->set_userdata($userdata);
//display log in successfull msg
$this->output->set_output(json_encode(array('status'=>true,'msg'=>'log in successfully','data'=>$userdata)));
}else{
//wrong username or password
$this->output->set_output(json_encode(array('status'=>false,'msg'=>'invalid Username or password')));
}
}else{
//when username and password not set
$this->output->set_output(json_encode(array('status'=>false,'msg'=>'provide Username and password')));
}
}