jeudi 25 février 2021

Checking if either of two statements are true

I am checking if a variable 'auth' is set on either _POST or _GET and want two different actions. I have managed to get it working with if / else but it looks ugly and wasteful?

If POST isn't set, check GET. If GET is set, do nothing <- that part doesn't look right?

if ( !isset( $_POST[ 'auth' ] ) ) 
{
  if (isset( $_GET[ 'auth' ] ) ) {
    //do nothing

  } else {
    //redirect
    header( 'Location: https://google.com' );
    exit();
  }
}

Is there a whole new approach here? Like check both, if neither are set go to redirect, if ONE is set continue with page?

if(isset($_GET['auth']) xor (isset($_POST['auth']))) {
    //do nothing
}else{
 //redirect
 header('Location: https://google.com');
 exit();
}

^ if these are acceptable statements, what should be in the 'do nothing' section?

Aucun commentaire:

Enregistrer un commentaire