是否不建议使用$ GLOBALS ['HTTP_GET_VARS']? [英] Is using $GLOBALS['HTTP_GET_VARS'] deprecated?

查看:128
本文介绍了是否不建议使用$ GLOBALS ['HTTP_GET_VARS']?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道使用 $ HTTP_GET_VARS 已过时,但使用 $ GLOBALS ['HTTP_GET_VARS']

I know that the use of $HTTP_GET_VARS is deprecated but what about using $GLOBALS['HTTP_GET_VARS']? Is that array key likely to disappear in the future?

我基本上在一个需要与CMS集成的旧项目中拥有以下内容,但我并不是真的

I basically have the following all over a legacy project that I need to integrate with a CMS and I don't really want to have to update it unless strictly necessary.

function table_manager_import_vars($var) {
   $vars = explode(",", $var);

   foreach($vars AS $var) {
       switch ($var) {
           case "G":
               $var = "HTTP_GET_VARS";
               break;
           case "P":
               $var = "HTTP_POST_VARS";
               break;
           case "C":
               $var = "HTTP_COOKIE_VARS";
               break;
           case "S":
               $var = "HTTP_SESSION_VARS";
               //session_start();
               break;
           case "E":
               $var = "HTTP_SERVER_VARS";
               break;
       }
       if (isset($GLOBALS[$var])) {
           if (is_array($GLOBALS[$var])) {
               foreach($GLOBALS[$var] AS $var1 => $value) {
                   if ($var1 != $var) {
                       $GLOBALS[$var1] = $value;
                   }
               }
           }
       }
   }
}
// called like this
table_manager_import_vars("G,P,C,S,E");

是的,您猜测它在项目的每个方面都有这样的功能,只是功能不同每次都命名!!!

And yes you guessed it there is a function like this for every aspect of the project just with a different name each time!!

推荐答案

您的问题:


是否不建议使用$ GLOBALS ['HTTP_GET_VARS']?

Is using $GLOBALS['HTTP_GET_VARS'] deprecated?

答案:

是的。

http://www.php.net/manual/zh/reserved.variables.get.php

此页明确指出 $ HTTP_GET_VARS 已被弃用,您应该改用 $ _ GET

This page explicitly states that $HTTP_GET_VARS has been deprecated and you should use $_GET instead.

$ HTTP_GET_VARS $ GLOBALS ['HTTP_GET_VARS'] 相同。因此,它也因为这个原因而被弃用。 (请注意,可以使用 $ GLOBALS ['variablename'] 引用在全局范围内定义的所有变量)

$HTTP_GET_VARS is the same thing as $GLOBALS['HTTP_GET_VARS']. And therefore it is also deprecated for the reason. (note that all variables defined at the global scope can be referenced using $GLOBALS['variablename'])

顺便说一句:当涉及使用 $ HTTP_GET_VARS 的旧代码时,我知道您说过您希望避免更改代码,但是这很值得指出这个时代的代码在现代PHP安装中运行时可能会遇到大问题,因为旧版本的PHP会假设正在使用 magic_quotes 之类的东西。如果在较新版本的PHP中运行相同的代码,则不会有 magic_quotes ,因此应确保数据正确转义。

By the way: When it comes to working with legacy code that uses $HTTP_GET_VARS, I know you said you want to avoid changing the code if you can avoid it, but it's worth pointing out that code of this age is likely to have big issues when run in a modern PHP installation, as older versions of PHP would have assumed things like magic_quotes being in use. If you run the same code in a newer version of PHP you won't have magic_quotes, so you should make sure the data is escaped properly.

查看那里的完整代码,似乎正在尝试复制各种 HTTP _ *** _ VARS 将数组放入全局范围。该功能是在 really 旧版本的PHP中自动完成的,但由于会引起大量的安全问题而被删除。我强烈建议删除全部代码,并将所有内容转换为使用 $ _ GET 。您可能想要 google for register_globals 有关为什么这是一件坏事的详细信息。

Looking at the whole code that you've got there, it looks like it's trying to copy all the variables in the various HTTP_***_VARS arrays into the globlal scope. This is functionality that was done automatically in really old versions of PHP, but was dropped because it causes massive security issues. I seriously recommend dropping that whole bit of code and converting everying to use $_GET instead. You might want to google for register_globals for more info on why this is a bad thing.

这篇关于是否不建议使用$ GLOBALS ['HTTP_GET_VARS']?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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