• 主页

# session_register()问题

antidestiny 2004-03-31 07:10:33

<?php
session_register('aaa');

phpinfo();
?>

Warning: session_register(): Cannot send session cookie - headers already sent by (output started at C:\Program Files\PHP Expert Editor\php160.tmp:3) in C:\Program Files\PHP Expert Editor\php160.tmp on line 4

Warning: session_register(): Cannot send session cache limiter - headers already sent (output started at C:\Program Files\PHP Expert Editor\php160.tmp:3) in C:\Program Files\PHP Expert Editor\php160.tmp on line 4

php.ini中的session.save_path也设置了,不知道怎么还是不行????
...全文
693 点赞 收藏 8

8 条回复

cloudchen 2004-04-01

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

ashchen 2004-04-01

ashchen 2004-04-01

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().

ninjakoei 2004-03-31
<?php
session_start();//这个最好要用在你所有使用session的PHP网页的最顶部，
session_register('aaa');

phpinfo();
?>

feel8 2004-03-31
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.

mistjin 2004-03-31

turtlevan 2004-03-31
1.

2.

2.1w+