Home > Backend Development > PHP Tutorial > php模仿asp Application对象在线人数统计实现方法_php技巧

php模仿asp Application对象在线人数统计实现方法_php技巧

WBOY
Release: 2016-05-16 20:26:44
Original
934 people have browsed it

本文实例讲述了php模仿asp Application对象在线人数统计实现方法。分享给大家供大家参考。具体实现方法如下:

复制代码 代码如下:
/*
用法:
application('key','value'); //设置 key=value
$value = application('key'); //获取 key的值
*/
 
function application()
{
 $args = func_get_args(); //获取输入参数
 if (count($args) >2 || count($args)  $ssid = session_id(); //保存当前session_id
 session_write_close(); //结束当前session
 ob_start(); //禁止全局session发送header
 session_id("xxx"); //注册全局session_id
 session_start(); //开启全局session
 $key = $args[0];
 if (count($args) == 2) //如果有第二个参数,那么表示写入全局session
 {
  $re = ($_session[$key] = $args[1]);
 }
 else // 如果只有一个参数,那么返回该参数对应的value
 {
  $re = $_session[$key];
 }
 session_write_close(); //结束全局session
 session_id($ssid); //重新注册上面被中断的非全局session
 session_start(); //重新开启
 ob_end_clean(); //抛弃刚刚由于session_start产生的一些header输出
 return $re; 
}

希望本文所述对大家的php程序设计有所帮助。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template