如何在PHP 5.4或更高版本中模拟register_globals? [英] How can I emulate register_globals in PHP 5.4 or newer?

查看:109
本文介绍了如何在PHP 5.4或更高版本中模拟register_globals?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究使用register_globals的框架.我的本地php版本是5.4.

I am working on a framework that uses register_globals. My local php version is 5.4.

我知道register_globals自PHP 5.3.0起已弃用,并已在PHP 5.4中删除,但是我必须使此代码在PHP 5.4上起作用.

I know register_globals is deprecated since PHP 5.3.0 and removed in PHP 5.4, but I have to make this code work on PHP 5.4.

有什么方法可以在较新版本的PHP上模拟该功能?

Is there any way to emulate the functionality on newer versions of PHP?

推荐答案

您可以使用提取来模拟register_globals.全局rel ="nofollow noreferrer">范围:

You can emulate register_globals by using extract in global scope:

extract($_REQUEST);

或者使用全局变量和变量变量将其置于独立函数中

Or put it to independent function using global and variable variables

function globaling()
{
    foreach ($_REQUEST as $key => $val)
    {
        global ${$key};
        ${$key} = $val;
    }
}

如果您拥有已发布的应用程序,并且不想更改其中的任何内容,则可以使用

If you have a released application and do not want to change anything in it, you can create globals.php file with

<?php
extract($_REQUEST);

然后添加 auto_prepend_file .htaccess指令(或在php.ini中)

then add auto_prepend_file directive to .htaccess (or in php.ini)

php_value auto_prepend_file ./globals.php

此后,代码将在每次调用时运行,并且应用程序将像旧设置一样生效.

After this the code will be run on every call, and the application will work as though the old setting was in effect.

这篇关于如何在PHP 5.4或更高版本中模拟register_globals?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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