Ecco qui di seguito una classe in PHP molto utile per eliminare i caratteri magici dai testi che i vostri script php processano. Viene utilizzata anche in GGuestBook e in NewsMaker.
L'autore non sono io, è di Andrea Giammarchi di
3site.it e modificato da me (è presente sul sito
3site.it la versione modificata da Andrea).
Ecco il codice.
File name: class.RemoveMagicQuotes.php
= PHP 4.0
* @Author Andrea Giammarchi
* @Site www.3site.it/
* @Mail andrea@3site.it
* @Date 01/06/2004
* @LastModified 07/02/2005
* @Version 1.0b
*/
class RemoveMagicQuotes {
/**
* Public constructor.
* RemoveMagicQuotes();
* @Param no no params need
*/
function RemoveMagicQuotes() {
if( get_magic_quotes_gpc() ) {
$this->__removeSlashes( $_GET );
$this->__removeSlashes( $_POST );
$this->__removeSlashes( $_COOKIE );
$this->__removeSlashes( $_REQUEST );
}
}
function __removeSlashes( &$what ) {
while( list( $key ) = each( $what ) ) {
if( is_Array( $what[$key] ) ) {
$this->__removeSlashes( $what[$key] );
}
else {
$what[$key] = stripslashes( $what[$key] );
}
}
}
}
?>
Grazie Andrea.