![Antiguo](http://static.forosdelweb.com/fdwtheme/images/statusicon/post_old.gif)
21/10/2011, 08:58
|
![Avatar de timoteo666](http://static.forosdelweb.com/customavatars/avatar433077_1.gif) | | | Fecha de Ingreso: agosto-2011 Ubicación: /home/Gdl
Mensajes: 242
Antigüedad: 13 años, 5 meses Puntos: 11 | |
Respuesta: es correcto hacer este tipo de limpieza?? Excelente recurso muchas gracias ![Afirmando](http://static.forosdelweb.com/fdwtheme/images/smilies/afirmar.gif) Cita:
Iniciado por marcofbb Yo lo que hago es automaticamente sacarle a todos los $_POST y demas variables. Como lo hace smf.
Te dejo el codigo:
Código PHP:
Ver original<?php /********************************************************************************** * QueryString.php * ***********************************************************************************/ // Clean the request variables - add html entities to GET and slashes if magic_quotes_gpc is Off. function cleanRequest() { //global $board, $topic, $boardurl, $scripturl, $modSettings, $smcFunc; global $msCore; // Makes it easier to refer to things this way. $scripturl = $msCore->settings['w_url'] . '/index.php'; // What function to use to reverse magic quotes - if sybase is on we assume that the database sensibly has the right unescape function! $removeMagicQuoteFunction = @ini_get('magic_quotes_sybase') || strtolower(@ini_get('magic_quotes_sybase')) == 'on' ? 'unescapestring__recursive' : 'stripslashes__recursive'; // Save some memory.. (since we don't use these anyway.) unset($GLOBALS['HTTP_POST_VARS'], $GLOBALS['HTTP_POST_VARS']); unset($GLOBALS['HTTP_POST_FILES'], $GLOBALS['HTTP_POST_FILES']); // These keys shouldn't be set...ever. if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS'])) die('Invalid request variable.'); // Same goes for numeric keys. die('Numeric request keys are invalid.'); // Numeric keys in cookies are less of a problem. Just unset those. foreach ($_COOKIE as $key => $value) // Get the correct query string. It may be in an environment variable... if (!isset($_SERVER['QUERY_STRING'])) $_SERVER['QUERY_STRING'] = getenv('QUERY_STRING'); // It seems that sticking a URL after the query string is mighty common, well, it's evil - don't. if (strpos($_SERVER['QUERY_STRING'], 'http') === 0) { header('HTTP/1.1 400 Bad Request'); } // If magic quotes is on we have some work... { $_ENV = $removeMagicQuoteFunction($_ENV); $_POST = $removeMagicQuoteFunction($_POST); $_COOKIE = $removeMagicQuoteFunction($_COOKIE); foreach ($_FILES as $k => $dummy) if (isset($_FILES[$k]['name'])) $_FILES[$k]['name'] = $removeMagicQuoteFunction($_FILES[$k]['name']); } // Add entities to GET. This is kinda like the slashes on everything else. $_GET = htmlspecialchars__recursive($_GET); $_POST = htmlspecialchars__recursive($_POST); $_COOKIE = htmlspecialchars__recursive($_COOKIE); // Let's not depend on the ini settings... why even have COOKIE in there, anyway? $_REQUEST = $_POST + $_GET; } // Adds slashes to the array/variable. Uses two underscores to guard against overloading. function escapestring__recursive($var) { global $smcFunc; // Reindex the array with slashes. // Add slashes to every element, even the indexes! foreach ($var as $k => $v) $new_var[addslashes($k)] = escapestring__recursive ($v); return $new_var; } // Adds html entities to the array/variable. Uses two underscores to guard against overloading. function htmlspecialchars__recursive($var, $level = 0) { // Add the htmlspecialchars to every element. foreach ($var as $k => $v) $var[$k] = $level > 25 ? null : htmlspecialchars__recursive($v, $level + 1); return $var; } // Unescapes any array or variable. Two underscores for the normal reason. function unescapestring__recursive($var) { // Reindex the array without slashes, this time. // Strip the slashes from every element. foreach ($var as $k => $v) return $new_var; } // Remove slashes recursively... function stripslashes__recursive($var, $level = 0) { // Reindex the array without slashes, this time. // Strip the slashes from every element. foreach ($var as $k => $v) $new_var[stripslashes($k)] = $level > 25 ? null : stripslashes__recursive ($v, $level + 1); return $new_var; } ?>
Y para pasarlo a la base de datos le agrego mysql_escape_string
Saludos
__________________ ( + ) lineas de código ( - ) televisión |