دوستان اگه بهتر می تونن. ادامه بدن
Printable View
دوستان اگه بهتر می تونن. ادامه بدن
یه تابع کاملتر برای چک کردن ورودی ها نوشتم که میتونید از این استفاده کنید . این کاملتره به نظرم:
[PHP]
function filter_html($what){
///.. BASIC ASCII Entities with new Entity Names
$what = str_replace( "&#" , "(^)-(^)" , $what );
$what = str_replace( "&" , "&" , $what );
$what = str_replace( ">" , ">" , $what );
$what = str_replace( "<" , "<" , $what );
$what = ereg_replace( "\"" , """ , $what );
$what = str_replace( "!" , "!" , $what );
$what = str_replace( "'" , "'" , $what );
$what = str_replace( "(^)-(^)" , "&#" , $what );
$what = str_replace("`" ,"" , $what );
$what = ereg_replace("\n" , "<br>" , $what );
$what = ereg_replace("\r" , "" , $what );
///.. ISO 8859-1 Symbol Entities
$what = str_replace("¡" , "¡" , $what );
$what = str_replace("¤" , "¤" , $what );
$what = str_replace("¢" , "¢" , $what );
$what = str_replace("£" , "£" , $what );
$what = str_replace("€" , "€" , $what );
$what = str_replace("¥" , "¥" , $what );
$what = str_replace("¦" , "¦" , $what );
$what = str_replace("§" , "§" , $what );
$what = str_replace("©" , "©" , $what );
$what = str_replace("¿" , "¿" , $what );
$what = str_replace("¶" , "¶" , $what );
///.. ISO 8859-1 Character Entities
$what = str_replace("À" , "À" , $what );
$what = str_replace("Á" , "Á" , $what );
$what = str_replace("Â" , "Â" , $what );
$what = str_replace("Ä" , "Ä" , $what );
$what = str_replace("Å" , "Å" , $what );
$what = str_replace("Æ" , "Æ" , $what );
$what = str_replace("Ç" , "Ç" , $what );
$what = str_replace("È" , "È" , $what );
$what = str_replace("É" , "É" , $what );
$what = str_replace("Ê" , "Ê" , $what );
$what = str_replace("Ë" , "Ë" , $what );
$what = str_replace("Ì" , "Ì" , $what );
$what = str_replace("Î" , "Î" , $what );
$what = str_replace("Ï" , "Ï" , $what );
$what = str_replace("Ð" , "Ð" , $what );
$what = str_replace("Ñ" , "Ñ" , $what );
$what = str_replace("Ò" , "Ò" , $what );
$what = str_replace("Ó" , "Ó" , $what );
$what = str_replace("Ô" , "Ô" , $what );
$what = str_replace("Õ" , "Õ" , $what );
$what = str_replace("Ö" , "Ö" , $what );
$what = str_replace("Ø" , "Ø" , $what );
$what = str_replace("Ù" , "Ù" , $what );
$what = str_replace("Ú" , "Ú" , $what );
$what = str_replace("Û" , "Û" , $what );
$what = str_replace("Ü" , "Ü" , $what );
$what = str_replace("Ý" , "Ý" , $what );
$what = str_replace("Þ" , "Þ" , $what );
$what = str_replace("ß" , "ß" , $what );
$what = str_replace("à" , "à" , $what );
$what = str_replace("á" , "á" , $what );
$what = str_replace("â" , "â" , $what );
$what = str_replace("à" , "á" , $what );
$what = str_replace("ä" , "ä" , $what );
$what = str_replace("å" , "å" , $what );
$what = str_replace("æ" , "æ" , $what );
$what = str_replace("ç" , "ç" , $what );
$what = str_replace("è" , "è" , $what );
$what = str_replace("é" , "é" , $what );
$what = str_replace("ê" , "ê" , $what );
$what = str_replace("ë" , "ë" , $what );
$what = str_replace("ì" , "ì" , $what );
$what = str_replace("í" , "í" , $what );
$what = str_replace("î" , "î" , $what );
$what = str_replace("ï" , "ï" , $what );
$what = str_replace("ð" , "ð" , $what );
$what = str_replace("ñ" , "ñ" , $what );
$what = str_replace("ò" , "ò" , $what );
$what = str_replace("ó" , "ó" , $what );
$what = str_replace("ô" , "ô" , $what );
$what = str_replace("õ" , "õ" , $what );
$what = str_replace("ö" , "ö" , $what );
$what = str_replace("ø" , "ø" , $what );
$what = str_replace("ù" , "ù" , $what );
$what = str_replace("ú" , "ú" , $what );
$what = str_replace("û" , "û" , $what );
$what = str_replace("ü" , "ü" , $what );
$what = str_replace("ý" , "ý" , $what );
$what = str_replace("þ" , "þ" , $what );
$what = str_replace("ÿ" , "ÿ" , $what );
///.. ISO 8859-1 Other Entities
$what = str_replace("Œ" , "Œ" , $what );
$what = str_replace("œ" , "œ" , $what );
$what = str_replace("Š" , "Š" , $what );
$what = str_replace("š" , "š" , $what );
$what = str_replace("˜" , "˜" , $what );
$what = str_replace("‘" , "‘" , $what );
$what = str_replace("’" , "’" , $what );
$what = str_replace("‚" , "‚" , $what );
// for some really strange reason this is replacing all characters:
$what = str_replace("Ã" , "Ã" , $what );
$what = str_replace("ã" , "ã" , $what );
return $what;
}
[/PHP]
و در ضمن تابع زیر رو زمانی میشه بکار برد که به ورودی اجازه کدهای html رو میدیم ولی اجازه ورود تگ های حساس رو منع می کنیم:
[PHP]
function filter_html_dangerous_tags($what){
$what = str_replace( "<script>" , "<script>" , $what );
$what = str_replace( "</script>" , "</script>" , $what );
$what = str_replace( "<object>" , "<object>" , $what );
$what = str_replace( "</object>" , "</object>" , $what );
$what = str_replace( "<iframe>" , "<iframe>" , $what );
$what = str_replace( "</iframe>" , "</iframe>" , $what );
$what = str_replace( "<frameset>" , "<frameset>" , $what );
$what = str_replace( "<frameset>" , "<frameset>" , $what );
$what = str_replace( "<frame>" , "<frame>" , $what );
$what = str_replace( "</frame>" , "</frame>" , $what );
$what = str_replace( "<link>" , "<link>" , $what );
$what = str_replace( "</link>" , "</link>" , $what );
return $what;
}
[/PHP]
سلام
چطوری میشه از این کدا استفاده کرد و در چه مواقعی
البته ببخشید اگه خیلی مبتدی هست سوالم
اگر میشه نحوه استفاده از این کدها رو هم توضیح بدید. الان من نمی دونم این کدهارو کجا کپی کنم تا سایتم اینهارو استفاده کنه...
ممنون