1.
确定<?php之前没有任何空格或者换行2.
先调用session_start();

解决方案 »

  1.   

    session_start()之前不能有输出。If you want your script to work regardless of register_globals, you need to instead use the $_SESSION array as $_SESSION entries are automatically registered. If your script uses session_register(), it will not work in environments where the PHP directive register_globals is disabled. 
      

  2.   

    <?php
    session_start();//这个最好要用在你所有使用session的PHP网页的最顶部,
    session_register('aaa');phpinfo();
    ?>
      

  3.   

    如果你的浏览器版本高就没这个问题了,IE6.0好像会忽略header重发的情况
    还有写入session的语句不要这样写了,关于session的新写法请查看相关资料
    老的教科书过时了
    下面是英文的一段描述,自己看看,如果看不懂英文就不要再写程序了,改行吧If you want your script to work regardless of register_globals, you need to instead use the $_SESSION array as $_SESSION entries are automatically registered. If your script uses session_register(), it will not work in environments where the PHP directive register_globals is disabled. register_globals: important note: 
    Since PHP 4.2.0, the default value for the PHP directive register_globals is off. The PHP community encourages all to not rely on this directive but instead use other means, such as the superglobals. Caution: 
    This registers a global variable. If you want to register a session variable from within a function, you need to make sure to make it global using the global keyword or the $GLOBALS[] array, or use the special session arrays as noted below. Caution: 
    If you are using $_SESSION (or $HTTP_SESSION_VARS), do not use session_register(), session_is_registered(), and session_unregister(). 
      

  4.   

    下载一份PHP手册最新版,最新的是12,CHM的,一定要英文的,中文的也可以备一份,不过翻译的不完整还有乱码,很多问题可以查一下,强迫自己看英文,chm有索引功能,比较方便。我觉得给人家猎物不如告诉人家狩猎的方法
      

  5.   

    1、session_register前一定要有session_start()
    2、确保被session_register的变量是全局变量
    3、session_register只适用于php4.0.x
      

  6.   

    应该在新版的php已经没必要用session_register了直接对$_SESSION["foo"]进行赋值/取值就可以了,和asp中一样。