Вход Регистрация
* RUSIKAN

Хороший антихак.

  1. <?php
  2. //by MASTERAM.US
  3. class AntiHack {
  4.  
  5. private $getarr = ''; // Ключ для распознавания массива
  6.  
  7. private $input = array(); // Массив для фильтрации
  8.  
  9. private $arraykey = 256; // максимальное количество символов в ключе массива
  10.  
  11. private $arrayvalue = 100000; // максимальное количество символов в значении массива
  12.  
  13. // Ключи для удаления из массива _SERVER
  14. private $arrayserverkey = 'COMSPEC;SYSTEMROOT;PATHEXT;UNIQUE_ID;PATH;GATEWAY_INTERFACE;SERVER_SIGNATURE;SERVER_ADMIN;PERL5LIB';
  15.  
  16.  
  17. function __construct()
  18. {
  19. $this->filter($this ->input, $this->getarr);
  20. }
  21.  
  22.  
  23. private function __cleaning($input, $keyss, $getarr)
  24. {
  25. if (!empty($input) && $keyss == 'value' && $getarr != 'post')$input = urldecode($input);
  26.  
  27. /****** $input = str_replace(array("\n", "\r", "\t"), null, trim($input));******/
  28.  
  29. $charset = mb_detect_encoding($input);
  30.  
  31. $input = (($charset != 'UTF-8')?iconv((($charset === 'ASCII')?'WINDOWS-1251':$charset), 'UTF-8', $input):$input);
  32.  
  33. if (!empty($input) && $keyss === 'key')
  34. {
  35. $input = preg_replace('#[^a-z0-9-_]+#i', null, $input);
  36. $input = (string)strip_tags($input);
  37.  
  38. }
  39. elseif (($getarr === 'get' || !empty($input)) && $keyss === 'value')
  40. {
  41.  
  42. if ($getarr === 'get')
  43. {
  44. $input = preg_replace('#[^(a-z0-9-_\(\)\&\=\?\;\:\.\/\]\[)|(\x7F-\xFF)|(\s)]+#is', null, $input );
  45.  
  46. $input = str_replace('../', '', $input);
  47. }
  48. elseif ($getarr === 'post')
  49. {
  50. $input = str_replace('javascript', 'jаvаsсriрt', $input);
  51. $input = htmlentities($input, ENT_QUOTES, 'UTF-8');
  52. $input = addslashes($input);
  53.  
  54. }
  55. elseif ($getarr === 'files')
  56. {
  57. if (!is_string($input))
  58. {
  59. $input = intval($input);
  60. }
  61. else
  62. {
  63. $input = preg_replace('#[^(a-zа-я0-9-_\(\)\&\=\?\;\:\.\/)|(\x7F-\xFF)|(\s)]+#is', null, $input );
  64. }
  65.  
  66. }
  67. elseif ($getarr === 'cookie')
  68. {
  69. $input = preg_replace('#[^a-z0-9-_]+#i', null, $input);
  70. }
  71. elseif ($getarr === 'server')
  72. {
  73. $input = str_replace('\\', '/', $input);
  74. $input = preg_replace('#[^a-z0-9-_\/\.\s\:\;\,\?\=\@]+#i', null, $input);
  75. }
  76. elseif ($getarr === 'request')
  77. {
  78. if (!is_string($input))
  79. {
  80. $input = intval($input);
  81. }
  82. else
  83. {
  84. $input = htmlentities($input, ENT_QUOTES, 'UTF-8');
  85. }
  86.  
  87. }
  88. else
  89. {
  90. $input = (string)htmlentities( $input, ENT_QUOTES, 'UTF-8');
  91. $input = strip_tags($input);
  92. }
  93. }
  94. /*else
  95.   {
  96.   $input = null;
  97.   }*/
  98.  
  99. return ( $input );
  100. }
  101.  
  102.  
  103.  
  104. private function __sorting($input, $getarr)
  105. {
  106. if (!is_array($input))return(null);
  107.  
  108. $arr_delete = explode(';', $this->arrayserverkey);
  109.  
  110. foreach($input as $key => $value)
  111. {
  112.  
  113. if ($getarr === 'server')
  114. {
  115. $key = strtoupper($key);
  116. for ($i = 0; $i < count($arr_delete); $i++)
  117. {
  118. if (strnatcasecmp($key, $arr_delete[$i]) === 0)$value = null;
  119. }
  120. }
  121.  
  122. if ((!$key || $key == '' || $value === null || isset($key{$this->arraykey})) || ($getarr === 'files' && !is_uploaded_file($input[$key]['tmp_name'])))continue;
  123.  
  124. if (!is_array($value)) {
  125. if (isset($value{$this->arrayvalue}))continue;
  126.  
  127. $result[$this->__cleaning($key, 'key', $getarr)] = $this->__cleaning($value, 'value', $getarr);
  128. }
  129. else {
  130. foreach($value as $item => $field) {
  131. if ($field === '' || $field === null || isset($item{$this->arraykey}) || isset($field{$this -> arrayvalue}))continue;
  132.  
  133. $value[$this->__cleaning($item, 'key', $getarr)] = $this->__cleaning($field, 'value', $getarr);
  134. }
  135. $result[$this->__cleaning($key, 'key', $getarr)] = $value;
  136. }
  137. }
  138. return ((isset($result) ? $result : null));
  139. }
  140.  
  141.  
  142.  
  143. function filter($input, $getarr)
  144. {
  145. if (count($input) === 0) {
  146. return(null);
  147. }
  148. $getarr = strtolower($getarr);
  149. $getarr = str_replace(' ', null, trim($getarr ));
  150. return ($this->__sorting($input, $getarr));
  151. }
  152.  
  153.  
  154.  
  155. }//By MASTERAM.US
  156. ?>
» Описание: Хороший антихак, специально для пользователей masteram.us ;)
» Время добавления: 19 Янв 2016 в 19:56
» Посмотров: 1758
» textarea
» Рейтинг: [+0 | -0]
Комментарии [2]
Онлайн: 2
Реклама