php - Check if $_POST is empty -


i realize question has been asked multiple times, none have resolved issue me.

i want check if values in $_post array empty except 2 (shostfirstname , shostlastname), , throw 400 error if there empty value. way can throw 400 error putting die() command after header command, 400 error no matter if there empty values or not.

foreach ($_post $key => $value) {     if (empty($value) || !isset($value) && $key != 'shostfirstname' || 'shostlastname') {         header("http/1.1 400 bad request");         break;     } } 

isset() return true if variable has been initialised. if have form field name value set username, when form submitted value "set", although there may not data in it.

instead, trim() string , test length

if("" == trim($_post['username'])){     $username = 'anonymous'; }   

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -