projectIncomplete projectIncomplete - 1 month ago 5
HTTP Question

Do we always need to check if post and get variables are set before reading/using them?

Consider the following example:

if ( isset($_POST['type']) && 'page' == $_POST['type'] )
return;


Do we need the
isset($_POST['type'])
check?

From what I've seen so far the following has the seem result:

if ( 'page' == $_POST['type'] )
return;


Or can this cause problems in certain situations?

Answer

Using "isset" is right approach otherwise it will throw warning: "index type is undefined". Also it checks whether array is empty or not.

isset() function will serve the replacement of two functions

if(!empty(your_array) && array_key_exists('type',$POST['type']))

So use this check to avoid further complications

Comments