codeigniter create protected api


Example

This API not accessible for public user, authentication is required

/***************************
this is protected api this is not accessible if you are not loged in
***************************/
public function protectedapi(){
  if($this->session->userdata('logged_in')){
    //this section only accessible when user loged in
    $this->output->set_output(json_encode(array('status'=>true,'msg'=>'Access allowed')));
  }else{
    $this->output->set_output(json_encode(array('status'=>true,'msg'=>'Access denied')));
  }
}

enter image description here