Possible Duplicate:
PHP detecting request type (GET, POST, PUT or DELETE)
This should be an easy one.
I have a script, and in the script I want to determine whether the request arrive via GET
or POST
method.
What is the correct way to do it?
I am thinking of using something like this
if (isset($_POST)) { // do post } else { // do get }
But deep in my heart I don't feel this is the right way. Any idea?
Use isset() method in PHP to test the form is submitted successfully or not. In the code, use isset() function to check $_POST['submit'] method. Remember in place of submit define the name of submit button. After clicking on submit button this action will work as POST method.
Or just use request()->isMethod('post') anywhere cause the function request() is registered globally in Laravel. Can be checked by request()->method === 'PUT' as well.
If you are working RESTfully, GET should be used for requests where you are only getting data, and POST should be used for requests where you are making something happen.
Better use $_SERVER['REQUEST_METHOD']
:
if ($_SERVER['REQUEST_METHOD'] === 'POST') { // … }
Use $_SERVER['REQUEST_METHOD']
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With