The example of this article tells the PHP imitate ASP Application Object online Statistics realization method. Share to everyone for your reference. The implementation methods are as follows:
Copy Code code as follows:
/*
Usage:
Application (' key ', ' value '); Set Key=value
$value = Application (' key '); Gets the value of the key
*/
function Application ()
{
$args = Func_get_args (); Get input parameters
if (count ($args) >2 | | count ($ARGS) < 1) return;
$ssid = session_id (); Save current session_id
Session_write_close (); End Current session
Ob_start (); Prevent global session from sending header
session_id ("xxx"); Register Global session_id
Session_Start (); Open Global Session
$key = $args [0];
if (count ($args) = = 2)//If there is a second argument, then the global session is written
{
$re = ($_session[$key] = $args [1]);
}
else//If there is only one argument, then return the value corresponding to the parameter
{
$re = $_session[$key];
}
Session_write_close (); End Global Session
session_id ($SSID); Re-registering a non-global session that was interrupted above
Session_Start (); Open again
Ob_end_clean (); Discard some header outputs just as a result of session_start
return $re;
}
I hope this article will help you with your PHP program design.