How do I say in php if a variable is not set then go to a different page and if it is then continue loading current page? (I can do if isset fine but for what i'm doing i need it the other way around) I know I should probably know this since it seems like it would be easy I'm just having a bit of trouble with it and figured someone here could tell me quickly and save me a long drawn out process of figuring what i'm doing wrong. Thank you
Try this one: <?php if($anyvariable){ echo "Variable is present"; }else{ echo "Variable is NOT present"; } PHP:
That's not right in all cases! Here's an example - if your url is http://test.test/?test then if($_GET['test']) PHP: will return false, cause the var has no value, but isset($_GET['test']) PHP: will return true, cause the var is set, though it's null. Just wanted to explain a bit further, cause that's important to know
Use: if (!isset($varname)) { } ! gives the opposite effect, so the following means 'not equal to': ($var1 != $var2) {
I prefer doing stuff on positive side. if(empty($variable)){ //do something } PHP: Returns FALSE if var has a non-empty and non-zero value. The following things are considered to be empty: * "" (an empty string) * 0 (0 as an integer) * "0" (0 as a string) * NULL * FALSE * array() (an empty array) * var $var; (a variable declared, but without a value in a class)