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也设置了,不知道怎么还是不行????
...全文
773 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
cloudchen 2004-04-01
  • 打赏
  • 举报
回复
应该在新版的php已经没必要用session_register了

直接对$_SESSION["foo"]进行赋值/取值就可以了,和asp中一样。
xuzuning 2004-04-01
  • 打赏
  • 举报
回复
1、session_register前一定要有session_start()
2、确保被session_register的变量是全局变量
3、session_register只适用于php4.0.x
ashchen 2004-04-01
  • 打赏
  • 举报
回复
下载一份PHP手册最新版,最新的是12,CHM的,一定要英文的,中文的也可以备一份,不过翻译的不完整还有乱码,很多问题可以查一下,强迫自己看英文,chm有索引功能,比较方便。

我觉得给人家猎物不如告诉人家狩猎的方法
ashchen 2004-04-01
  • 打赏
  • 举报
回复
如果你的浏览器版本高就没这个问题了,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().

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
  • 打赏
  • 举报
回复
同上!!!session_start();
turtlevan 2004-03-31
  • 打赏
  • 举报
回复
1.
确定<?php之前没有任何空格或者换行

2.
先调用session_start();

21,893

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧