如何修复 session_register() 已弃用的问题? [英] How to fix the session_register() deprecated issue?
问题描述
如何修复 PHP 5.3 中 session_register()
已弃用的问题
How to fix the session_register()
deprecated problem in PHP 5.3
推荐答案
不要使用它.说明说:
在当前会话中注册一个或多个全局变量.
Register one or more global variables with the current session.
我想到了两件事:
- 使用全局变量无论如何都不好,想办法避免它们.
- 您仍然可以使用
$_SESSION['var'] = "value"
设置变量.
- Using global variables is not good anyway, find a way to avoid them.
- You can still set variables with
$_SESSION['var'] = "value"
.
另请参阅手册中的警告:
如果你想让你的脚本在不考虑 register_globals
的情况下工作,你需要使用 $_SESSION
数组,因为 $_SESSION
条目是自动的挂号的.如果您的脚本使用 session_register()
,它将在禁用 PHP 指令 register_globals
的环境中不工作.
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 usessession_register()
, it will not work in environments where the PHP directiveregister_globals
is disabled.
这很重要,因为register_globals
指令已设置默认为 False
!
This is pretty important, because the register_globals
directive is set to False
by default!
进一步:
这会注册一个 global
变量.如果要从 函数 中注册会话变量,则需要确保使用 global
关键字或 $GLOBALS[]<将其设为全局变量/code> 数组,或使用如下所述的特殊会话数组.
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 theglobal
keyword or the$GLOBALS[]
array, or use the special session arrays as noted below.
和
如果您使用 $_SESSION
(或 $HTTP_SESSION_VARS
),请勿使用 session_register()
、session_is_registered()
和 session_unregister()
.
If you are using
$_SESSION
(or$HTTP_SESSION_VARS
), do not usesession_register()
,session_is_registered()
, andsession_unregister()
.
这篇关于如何修复 session_register() 已弃用的问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!