先test1.php再test2.php,第一个执行完了,内存空间就释放了,global $a就消失了。
再执行test2.php的时候又声明了global $a但是没有赋值。所以echo 不出来东西。

解决方案 »

  1.   

    global.php:
    <?
    session_start();
    ?>
    test1.php:
    <?
    include('global.php');
    $_SESSION['a']='333';
    ?>
    test2.php:
    <?
    include('global.php');
    echo $_SESSION['a'];
    ?>
      

  2.   

    global.php:
    <?
    global $a;
    ?>
    test1.php:
    <?
    include"gobal.php";
    $a='333';
    ?>test2.php:
    <?
    include"test1.php";
    echo $a;
    ?>
      

  3.   

    请问,我的页面已经有输出了!我能用,session吗?!
    如果我的test1.php过于复杂,会不会影响速度?!
      

  4.   

    有输出的话在开头加ob_start();
      

  5.   

    使用$GLOBALS['hehe'] = 'haha';
      

  6.   

    如果怕过于复杂的话,用include_once函数,意思是只包含一次(在如果已包含了的话)
      

  7.   

    比如,我要显示我的第5条新闻的方法是:wenzhang.php?id=5
    而我想的是用wenzhang.php就可以了.把id=几用变量的形式带过去.