如何解决session_register()弃用的问题? [英] How to fix the session_register() deprecated issue?

查看:128
本文介绍了如何解决session_register()弃用的问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何解决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.

我想到两件事:

  1. 使用全局变量无论如何都不是一件好事,找到一种避免它们的方法.
  2. 您仍然可以使用$_SESSION['var'] = "value"设置变量.
  1. Using global variables is not good anyway, find a way to avoid them.
  2. 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 uses session_register(), it will not work in environments where the PHP directive register_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 the global 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 use session_register(), session_is_registered(), and session_unregister().

这篇关于如何解决session_register()弃用的问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆