import_request_variables

(PHP 4 >= 4.1.0, PHP 5 < 5.4.0)

import_request_variablesGET/POST/쿠키 변수를 전역으로 가져옵니다

설명

bool import_request_variables ( string $types [, string $prefix ] )

GET/POST/쿠키 변수를 전역으로 가져옵니다. register_globals을 사용하지 않지만, 몇몇 변수를 전역에서 사용하고 싶을 때 유용합니다.

SERVER 등의 다른 변수를 전역으로 가져오고 싶다면, extract()를 사용하십시오.

인수

types

types 인수를 사용하여, 어떠한 요청 변수를 가져올지 지정할 수 있습니다. 'G', 'P', 'C' 문자가 GET, POST, 쿠키에 대응합니다. 대소문자는 구별하지 않기 때문에 'g', 'p', 'c,'의 조합도 사용할 수 있습니다. POST는 POST 업로드 파일 정보도 포함합니다.

Note:

문자 순서에 주의하십시오. "gp"를 사용하면, POST 변수가 동일한 이름을 가지는 GET 변수를 덮어씌웁니다. GPC 이외의 모든 문자는 무시합니다.

prefix

전역으로 가져오는 모든 변수의 이름 앞에 붙이는 변수명 prefix입니다. "userid"라는 GET 값을 가지고 prefix에 "pref_"를 넘기면, 전역 변수 이름은 $pref_userid가 됩니다.

Note:

prefix 인수는 선택적이지만, prefix를 지정하지 않거나 빈 문자열을 지정하면, E_NOTICE가 발생합니다. 이는 보안 문제가 발생하기 때문입니다. Notice 오류는 기본 오류 보고 레벨에서는 표시되지 않습니다.

반환값

성공 시 TRUE를, 실패 시 FALSE를 반환합니다.

예제

Example #1 import_request_variables() 예제

<?php
// GET과 POST 변수를
// "rvar_" prefix로 가져옵니다.
import_request_variables("gp""rvar_");

echo 
$rvar_foo;
?>

참고

add a note add a note

User Contributed Notes 6 notes

up
8
ceo AT l-i-e DOT com
19 years ago
Call me crazy, but it seems to me that if you use this function, even WITH the prefix, then you might as well just turn register_globals back on...

Sooner or later, somebody will find a "hole" with your prefixed variables in an un-initialized variable.

Better to import precisely the variables you need, and initialize anything else properly.
up
5
brian at enchanter dot net
19 years ago
import_request_variables does *not* read from the $_GET, $_POST, or $_COOKIE arrays - it reads the data directly from what was submitted. This is an important distinction if, for example, the server has magic_quotes turned on and you massage the data to run stripslashes on it; if you then use import_request_variables, your variables will still have slashes in them.

In other words: even if you say $_GET=""; $_POST=""; then use import_request_variables, it'll still get all the request data.

If you change the contents of $_GET and you then want to bring this data into global variables, use extract($_GET, EXTR_PREFIX_ALL, "myprefix") instead.
up
0
rustamabd at gmail dot com
11 years ago
import_request_variables() is gone from PHP since version 5.4.0. A simple plug-in replacement it extract().

For example:

import_request_variables('gp', 'v_');

Can be replaced with:

extract($_REQUEST, EXTR_PREFIX_ALL|EXTR_REFS, 'v');
up
-1
jason
18 years ago
reply to ceo AT l-i-e DOT com:

I don't think it's a risk, as all of your request variables will be tagged with the prefix. As long as you don't prefix any of your internal variables with the same, you should be fine.

If someone tries to access an uninitiated security-related variable like $admin_level through request data, it will get imported as $RV_admin_level.
up
-2
samb06 at gmail dot com
17 years ago
What i do is have a small script in my header file that takes an array called $input, and loops through the array to extract variables. that way the security hole can be closed, as you specify what variables you would like extracted

$input = array('name' => null, 'age' => 26) ;

// 26 is the default age, if $_GET['age'] is empty or not set

function extract_get()
    {
        global $input ;
       
        if ($input)
            {
                foreach ($input as $k => $v)
                    {
                        if ($_GET[$k] == '' or $_GET[$k] == NULL)
                            {
                                $GLOBALS[$k] = $v ;
                            }
                        else
                            {
                                $GLOBALS = $_GET[$k] ;
                            }
                    }
            }
    }
up
-3
cornflake4 at gmx dot at
19 years ago
oops, a typo in my comment:

The last line in the second example (the on using the extract() function) should read:

echo $_GET['var']; # prints 1, so $_GET has been unchanged
To Top