CodeIgniter Forums

Full Version: How to force POST verb only for action method
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]deepakaggarwal[/eluser]
I've a method in controller which I want to respect only POST requests. If its a GET request it should actually be 404 Not found. How can I accomplish this?

thanks

El Forum

[eluser]pickupman[/eluser]
How about checking to see if the _POST array is greater than 1 otherwise show_404().

El Forum

[eluser]Sagar Ratnaparkhi[/eluser]
Yes, you can do it like

Code:
if(!empty($this->input->get()) && count($this->input->get()) > 0 )
  show_404();

El Forum

[eluser]deepakaggarwal[/eluser]
I did
Code:
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
    show_404();
}
else
{
//my code
}
thanks all!

Reason I was looking for this: I want to have a controller which displays form when GET otherwise performs operation. For example, GET:// AddUser() will display new user form while POST:// AddUser() will perform operation and display thank you. This will help me in having one action method and play with verbs.