p1.phpclass RunCodeInfo
{
public static $num=1;
public static function bown()
{
self::$num ++;
echo "val=".self::$num."<br/>";
}
}b1.php和b2.php<?php
include("p1.php");
RunCodeInfo::bown();
?>可是调用b1.php和b2.php页面每次都是重新开始的,
有没有办法定义像全局一样的类?让它每次累加,谢谢!

解决方案 »

  1.   

    一个页面是一个程序。
    页面与页面之间,只能用GET,POST,SESSION,cookie或者文件、数据库的方式传递数据。
      

  2.   

    不是想要页面的GET,POST,SESSION,cookie,我想要的是全局性的变量,就是这个变量停留在内存,不管多数页面的访问,有这个变量的,就呈现最新值,就像C#的static变量一样
      

  3.   

    <?php
    header('Content-Type:text/html;charset=utf-8');
    function Counter($counterFile) 
    {
    $num=0;
    if(file_exists($counterFile))
    {
    $num=file_get_contents($counterFile);
    $num++;
    file_put_contents($counterFile,$num);
    }
    else
    {
    file_put_contents($counterFile,$num);
    }
    echo ($num);
    }
    $counterFile =  "counter.txt";
    Counter($counterFile);?>
    这样吧
      

  4.   

    即使是利用文件、数据库保存,但它不知道服务器是否再启动了,例如:服务器刚启动时,我让先访问的第一个用户执行php的一块代码,第二个开始就不让访问了,有别的办法吗?
      

  5.   

    你只能记录到外面。。其实你生成个 LOCK文件也行。。好多 程序的 安装页面都有这样的功能。