PHP中session_register()出错的解决办法
PHP中session_register()出错的解决办法
错误提示:warning: unknown(): your script possibly relies on a session side-effect which
existed until php 4.2.3. please be advised that the session extension does not
consider global variables as a source of data, unless register_globals is
enabled. you can disable this functionality and this warning by setting
session.bug_compat_42 or session.bug_compat_warn to off, respectively. in unknown on line 0
1、php4.2以上版本不需要用session_register()注册session变量,直接用:
$_session["string"]=“string";
赋值。
2、用$_session["string"]获取变量值。
3、用$_session["string"][$n]可传递session数组。
两个测试页面:
//a.php
session_start();
echo $_session["x"]++;
//b.php
session_start();
echo $_session["x"];
运行a.php并不断刷新它,看看有什么结果
运行b.php看看能否在页面之间传送结果。
注意:a.php和b.php必须是同一个ie进程!
测试在register_globals = off下进行,一切正常。
Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3.
Please be advised that the session extension does not consider global variables as a source
of data, unless register_globals is enabled. You can disable this functionality and this
warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively. in
Unknown on line 0
这个错误警告是说:自php 4.2.3起,自动魔术变量转换功能默认关闭。register_globals=off
而传统的session *** 作需要这个开关是打开的。解决方法:
session_start();
$_SESSION['youVar'] = 'youVariableValue';2楼的说对的,是session_register 注册的问题,但是如果不用session_register 那用什么注册?
自问自答
若想取得从另一页面提交的变量:
方法一:在PHP.ini中找到register_global,并把它设置为on.
方法二:在接收网页最前面放上这个extract($_POST);extract($_GET);(注意extract($_SESSION)前必须要有Session_Start()).
方法三:用$_SESSION()注册变量