isset function for dumb

Saturday, May 15, 2010 |

this another example



$title = "voip phones";
$check = (isset($_GET['view']) ? true : false) ;
if($check){
echo "this page talk about voip";
}


last exampel is wrong because isset function already return bool (true | false)

this is true exampel

$title = "voip phones";
$check = isset($_GET['view']) ; // just check var by isset function
if($check){
echo "this page talk about voip";
}

isset php function

Sunday, May 9, 2010 |


iseset function : check if variable is (set | available) or not empty in your php script and return bool (true | false) result


exampel :


$var = 0 ;
if(isset($var)){
echo 'variable "$var" is available to use';
}else{
echo 'variable "$var" isn\'t available to use';
}

result :

variable "$var" isn't available to use


another example :


// we didn't create variable "$var"

if(isset($var)){
echo 'variable "$var" is available to use';
}else{
echo 'variable "$var" isn\'t available to use';
}

result :

variable "$var" isn't available to use


isset it's very important function to check if your variable is okay to use or not

exampel : isset function

|


error_reporting(E_ALL & ~E_NOTICE);
define(THIS_SCRIPT,'index.php');
define(INC,'./includes');
include_once('global.php');
include_once(INC."/class.block_control.php");

$area_r = $HTTP_SERVER_VARS['REQUEST_URI'] ;
setcookie ("area_re", $area_r,time()+360);
$block = new block_control('global');
$dir = '.';




$title = $setting['sitename'] ;
$do = $_GET['do'];

if(!isset($do)){
exit("you should be set var 'do' ");
}


//checking loop
if(!$userinfo['uid']) $do = 'notLogin';
elseif(!$userinfo['allow-add']) $do = 'NotAllow';
elseif(!$userinfo['email-active']){
header("Location: usercp?do=activeMail");
exit();
}elseif(!$userinfo['complete_profile']){
header("Location: usercp?do=complete");
exit();
}


switch($do){


case "NotAllow":
$left = $tpl->return_output('usercp/msg.tpl');
break;

case "complete":
$left = $tpl->return_output('usercp/msg-complete.tpl');
break;

case "activeMail":
$left = $tpl->return_output('usercp/msg-activeMail.tpl');
break;

}



$tpl->print_output('main.tpl');
$db->close();