Php global variable based on file system and serialize method. It is similar to Application variable of ASP or ASP.NET Technology

2 views
Skip to first unread message

zeesh...@gmail.com

unread,
Aug 2, 2006, 5:33:45 PM8/2/06
to phpguru
<?
/*
PHP Global Variable

This function is used to defined global variable based on file system
and can be accessed anywhere in the file. It is similar to Application
variable of ASP or ASP.NET Technology.

The directory temp dir should have 777 permission.

*/

function appVar($action,$temp_path,$varname,$value=""){
if($action == "set"){
if(!(fwrite(fopen($temp_path . $varname, 'w'),serialize($value))))
echo "[Error: file system/permission problem : $temp_path.$varname]";
$state = "";
}
if($action == "get"){
if(!($strvalue = implode("",file($temp_path . $varname)))) echo
"[Error: retrieving problem, file : $temp_path.$varname]";;
$value = unserialize($strvalue);
$state = $value;
}
return $state;
}

// Example
appVar("set","/temp","username","Zeeshan");
echo appVar("get","/temp","username","");

?>

Reply all
Reply to author
Forward
0 new messages