Como se mencionó antes, la primera cosa que parece venir a la mente es la forma no estándar de transmitir la información. lo que generará algunas dificultades al analizar los valores.Aunque, para mí, el principal problema no es verificar/sanitar/limpiar los datos en $ _GET. Puede ser que sea demasiado obvio y dado que casi todas las respuestas han sido dadas por personas que parecen saber lo que están haciendo, supongo que simplemente no lo mencionaron por eso
Pero recuerde que si no lo hace Verifíquelo, usted es vulnerable a ataques y mal funcionamiento de su script. La magnitud del daño depende de su propia aplicación, por lo que no es fácil de predecir.
En cualquier caso, esto es lo que voy a hacer, incluyendo el html
<?php
// initialize variables
$variable_1 = false; // assume this is the page you want to load
$variable_2 = false;
$default = 'index.php'; // the idea is to load something controlled by you. index, error, 404, etc.
// process $_GET, check, clean and assign values
if (isset($_GET) !== false) {
foreach ($_GET as $keys => $values) {
// check both, $keys and $values for; character set, length, validity against a white list, content
// using an if to match the $keys garantees that regardless of the order, you will get what you want
if ($keys === 'field_1') {
// do what you have to do with this, for instance ...
$variable_1 = $values;
}
if ($keys === 'field_2') {
// do what you have to do with this, for instance ...
$variable_2 = $values;
}
unset($_GET[$keys]);
}
unset ($keys, $values);
}
// check there are no surprises on $_GET. Load and study anything here
if (empty($_GET) === false) {
// it should be empty, so log what is in here and prepare your code for that
unset($_GET);
} else {
unset($_GET);
}
// process the variables according to what you want to do
// if there are just a few options, and they are not going to change often
// use a switch, otherwise, use a method to check if a file/content exists
// for the request and load it. If it doesn't exist, inform the user
// with out giving away internals and suggest a new destination
// process other variables, here or before this part, wherever makes sense
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>testing get</title>
</head>
<body>
<form method="get" action="test_get_00.php" accept-charset="utf-8">
<p><label for="field_1">write something<input type="text" id="field_1" name="field_1" /></label></p>
<p><label for="field_2">write something<input type="text" id="field_2" name="field_2" /></label></p>
<p><button type="submit">send</button></p>
</form>
</body>
</html>
Por supuesto que puede hacer algunas cosas más, pero si usted prepara su forma adecuada, incluyendo el conjunto de caracteres, tener menos preocupaciones, o al menos algunos elementos más conocidos. No es a prueba de fallas, pero ayuda.
Además, los mecanismos que mencioné anteriormente funcionan en una mentalidad de lista blanca, esa es la idea del foreach, para verificar que obtenga lo que espera y descartar el resto, después de iniciar sesión.
puede usted llamar print_r ($ _ GET) y mostrar lo que es ¿impreso? –