Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is it safe to check if a form is submitted with below code?
PHP
if( $_SERVER['REQUEST_METHOD'] === 'POST' )  

When I write this in Netbeans it suggests to use some filtering function. Is it necessary to do something like
PHP
$RequestMethod = filter_input(INPUT_SERVER, 'REQUEST_METHOD', FILTER_SANITIZE_STRING);
if ( $RequestMethod === 'POST' )
{
// Form data is posted to the page so ...
}

And I don't clearly understand the 3rd parameter here. What kind of filtering should I use?
Posted
Updated 12-May-15 22:24pm
v3
Comments
ZurdoDev 12-May-15 8:41am    
Why do you want to know this? In all my years doing web development I don't recall ever needing to do this so perhaps what you want should be done a different way.
cs101000 12-May-15 9:12am    
Well, I usually put the form submission logic in this 'if' block in order to make sure this is executed only when the form is submitted (and not when it is loaded for user input). I think this will make it more efficient and accurate, won't it? You are probably doing that with isset function.
ZurdoDev 12-May-15 9:28am    
Maybe this is a php thing so perhaps it is more common. I do not do php.
Mohibur Rashid 13-May-15 4:44am    
Why bothering with REQUEST_METHOD at all? If your request_method has anything other than GET, POST, HEADER OR DELETE then your apache will deal with it. There is a chance that your apache settings won't allow DELETE at all. For method HEADER i am not sure who handle. Why calling extra function to deal with it?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900