--------------------------------------

State Management In Php

--------------------------------------

//State Manage:means tracking user state(location path) where user migrated.

// Two Types of state: previous and forward state

How Many Ways we can Handle State


//1. using url

//2. session 

//3. File Handling


using Url:

-----------

we maintain the state or current url of user using Query String

state should be maintain from the page itself 

action="valid-upload.php?/=<?php echo basename($_SERVER['PHP_SELF']);?>

or 

<a href="target.php?/=<?php echo basename($_SERVER['PHP_SELF'])?>">


Make a Key in url and note down the Current Page name or its url

header("location:{$_REQUEST['/']}");


then you can header(location) using keyname /

for example

header("location:{$_REQUEST['/']}")


Checking set and unset varible

--------------------------------

<?php


//isset : is set return true or false for weather if a varible is defined or not

$x=10;

var_dump(isset($x));


//unset : same reverse of isset it destroys the defined varible or key.

echo "<hr/>";

$b='ravi';

echo "<hr/>";

echo $b;

echo "<hr/>";

var_dump(isset($b));

echo "<hr/>";

unset($b); // destroy

echo $b; // undefined Index $b : Notice Error

echo "<hr/>";

var_dump(isset($b));


How to set default value to a undefined varible

we are going to use ternary Operator for such logic


General Syntax:

---------------

<expression>?[true]:[false];


<?php


$x=5;

($x%2==0)?print("even"):print("odd");

//it is short version of if-else



//if value is unset then undefined index error will raise.

// we need to handle that 

// there are two possible ways

// 1. suppress Operator @

// 2. using Ternary to handle unset varible


//1. Suppress Operator : (@) is used to hide Notice or Warning Error

//2. Ternary Operator: can be to assign a default value if they not defined

// Special Care must be taken for Get Varible


Difference Btw is_null Empty and isset

Note:: empty($name) or $name=="" same

Note: In php NULL IS NOT EQUAL TO BLANK

NOTE:: In php BLANK = = EMPTY == '' OR ""


empty() : blank is not allowed isset() True $name="";

is_null() : varible is defined with value NULL  $name=NULL isset() True

isset() : varible is defined 

isset > empty() >is_null