How to check HTTP request method in codeigniter

No comments
Sometimes, we need to check HTTP request method in codeigniter while we are working on a form that accept user inputs and we want to validate if form is submitted correctly and match the request method we already defined.

Here is the code to detect request method using codeigniter inbuilt functions

 $this->input->server('REQUEST_METHOD');  
and an example:
 if($this->input->server('REQUEST_METHOD')=="POST"){  
 }  

In codeigniter 3, using method() is also possible to detect request method


 echo $this->input->method(TRUE); // Outputs: POST  
 echo $this->input->method(FALSE); // Outputs: post  
 echo $this->input->method(); // Outputs: post  

No comments :

Post a Comment