Cytat(empathon @ 21.10.2008, 16:11:53 )

Mistrzu...
<?php
$_POST['product_id'] = 'libgd<script>';
?>
Edit:
Sprawdź sobie czy może klasa korzysta z $HTTP_POST_VARS albo co jeszcze gorzej z register globals
Przecież to dokładnie to samo co ja zrobiłem, żeby przypisać wartość do pola super-globalnej tablicy $_POST, tylko że inaczej zapisane. Poza tym test zerżnąłem z manual'a PHP.
http://pl2.php.net/manual/pl/function.filter-input-array.phpCytat
/* data actually came from POST
$_POST = array(
'product_id' => 'libgd<script>',
'component' => '10',
'versions' => '2.0.33',
'testscalar' => array('2', '23', '10', '12'),
'testarray' => '2',
);
*/
I tak jak napisałem w pierwszym poście. Moja klasa Filter to tylko obiektowe opakowanie wbudowanych w PHP (od 5.2) funkcji filter_* ( np. filter_input )
<?php
class Filter extends Filter_Constants
{
/**
* Checks if variable of specified type exists
* Representation of filter_has_var() function
* @param integer $type
* @param string $variable_name
* @return boolean
*/
public static function hasVar
($type, $variable_name) {
return filter_has_var($type, $variable_name);
}
/**
* Returns the filter ID belonging to a named filter
* Representation of filter_id() function
* @param string $filtername
* @return integer or null
*/
public static function id
($filtername) {
return filter_id($filtername);
}
/**
* Gets external variables and optionally filters them
* Representation of filter_input_array() function
* @param integer $type
* @param mixed $definition
* @return mixed
*/
public static function inputArray
($type, $definition = null) {
return filter_input_array($type, $definition);
}
/**
* Gets a specific external variable by name and optionally filters it
* Representation of filter_input() function
* @param integer $type
* @param string $variable_name
* @param integer $filter
* @param mixed $options
* @return mixed
*/
public static function input
($type, $variable_name, $filter = null, $options = null) {
if($filter !== null)
{
if($options !== null)
{
$out = filter_input($type, $variable_name, $filter, $options);
} else {
$out = filter_input($type, $variable_name, $filter);
}
} else {
$out = filter_input($type, $variable_name);
}
return $out;
}
/**
* Returns a list of all supported filters
* Representation of filter_list() function
* @return array
*/
public static function getList
() {
return filter_list();
}
/**
* Gets multiple variables and optionally filters them
* Representation of filter_var_array() function
* @param array $data
* @param mixed $definition
* @return mixed
*/
public static function variableArray
($data, $definition = null) {
if($definition === null)
{
$out = filter_var_array($data);
} else {
$out = filter_var_array($data, $definition);
}
return $out;
}
/**
* Filters a variable with a specified filter
* Representation of filter_var() function
* @param mixed $variable
* @param integer $filter
* @param mixed $options
* @return mixed
*/
public static function variable
($variable, $filter = null, $options = null) {
return filter_var($variable, $filter, $options);
}
}
?>
Wszystko mi zaczęło działać kiedy do testowania wykorzystałem prosty formularz, wysyłający jedno pole metodą post.
Stąd moja ciekawość. W jaki sposób funkcje filter_* dostają się do wartości z tablic super-globalnych. Skoro funkcja nie widzi wartości zmiennej, jeśli ją przypiszę wewnątrz skryptu. Czyli na przykład tak jak podał
empathon.