问题描述:

$Var = new StdClass;

if($_POST['somvar']){

$Var->somvar = $_POST['somvar']

}

else

{

$somevar=''

}

Why is it creating hidden varaible for this statement

"$Var->somvar = $_POST['somvar']"

when i see the view source

How do i persist the state of this variable when moving to next pages

网友答案:

The answer to your second question is probably sessions.

session_start();

$Var = new StdClass;

if($_POST['somvar']){
$Var->somvar = $_POST['somvar']
}

// Objects need to be serialized to be stored in $_SESSION
$_SESSION["Var"] = serialize ($Var);

to access $Var on another page:

session_start();

if (array_key_exists("Var", $_SESSION))
 $Var = unserialize($_SESSION["Var"]);

if (!empty($Var->somvar))
 echo "Somvar is: ".$Var->somvar;   
相关阅读:
Top