Home >php教程 >php手册 >php模仿asp Application对象在线人数统计

php模仿asp Application对象在线人数统计

WBOY
WBOYOriginal
2016-05-25 16:38:431043browse

<?php
/*
用法: 
application(&#39;key&#39;,&#39;value&#39;); //设置 key=value 
$value = application(&#39;key&#39;); //获取 key的值 
*/
function application() {
    $args = func_get_args(); //获取输入参数
    //开源代码phprm.com
    if (count($args) > 2 || count($args) < 1) return;
    $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;
}


本文链接:

收藏随意^^请保留教程地址.

Statement:
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