如何解决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
指令设置为默认!
This is pretty important, because the register_globals
directive is set to False
by default!
进一步:
这将注册一个
global
变量.如果要在函数中注册会话变量,则需要确保使用global
关键字或$GLOBALS[]
数组将其设置为全局变量,或者使用指定的特殊会话数组在下面.
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屋!