I have come across scripts that use:
isset($_POST['submit'])
as well as code that uses:
$_SERVER['REQUEST_METHOD']=='POST'
I was wondering the difference between these two and which method is best.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
These mean two different things. The first, checks to see if when the form was submitted the parameter
submitwas passed. Many use this snippet to verify that a form has been sent. This works because the submit button is technically an<input>so it’s value is sent along with any other elements that were part of the form.The second snippet tests if the form was submitted with the POST method. This doesn’t necessarily mean that the form button was pushed. If it wasn’t submitted with POST, then the superglobal
$_POSTwould be empty.