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');
(PHP 4 >= 4.1.0, PHP 5 < 5.4.0)
import_request_variables — GET/POST/Çerez değişkenlerini küresel etki alanına dahil eder
$türler
[, string $önek
] )GET/POST/Çerez değşkenlerini küresel etki alanına dahil eder. register_globals yönergesine 'Off' atadıysanız fakat bazı değişkenleri küresel etki alanında görmek istiyorsanız bu işlev işinize yarayacaktır.
$_SERVER gibi başka değişkenleri de küresel etki alanına dahil etmek isterseniz extract() işlevini kullanabilirsiniz.
türler
türler değiştirgesini kullanarak küresel etki
alanına dahil edeceğiniz istek değişkenlerini belirtebilirsiniz. GET,
POST ve Cookie için sırayla 'G', 'P' ve 'C' karakterlerini
belirtebilirsiniz. Bu karakterlerin büyük veya küçük harf olmasının bir
önemi yoktur. POST, karşıya yüklenen dosya bilgisini dahil eder.
Bilginize:
Harflerin veriliş sırası önemlidir. Örneğin, "GP" olarak belirtilirse, aynı isimli POST değişkenleri GET değişkenlerinin üzerine yazar. GPC dışındaki diğer karakterler iptal edilir.
önekKüresel etki alanına dahil edilen tüm değişken isimlerinin önüne getirilecek dizge. Örneğin, "userid" isimli bir GET değeri varsa ve önek olarak "pref_" belirtmişseniz $pref_userid isimli bir küresel değişkeniniz olur.
Bilginize:
önekdeğiştirgesi isteğe bağlı olmakla birlikte bir önek belirtmezseniz veya önek olarak boş bir dizge belirtirsenizE_NOTICEseviyesinde bir uyarı alırsınız. Bu, olası bir güvenlik riskidir. Uyarı seviyesinden hataların gösterilmesini öntanımlı hata raporlama seviyesiyle engelleyebilirsiniz.
Başarı durumunda TRUE, başarısızlık durumunda FALSE döner.
Örnek 1 - import_request_variables() örneği
<?php
// Bu satır, GET ve POST değişkenlerini "rvar_"
// önekiyle küresel etki alanına dahil edecektir
import_request_variables("gp", "rvar_");
echo $rvar_foo;
?>
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');
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.
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.
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] ;
}
}
}
}
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.
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